User:SignpostMarv Martin/is uuid comparison

From Second Life Wiki
< User:SignpostMarv Martin
Revision as of 10:28, 29 July 2008 by SignpostMarv Martin (talk | contribs) (New page: <div style="font-size:1.4em;"> == regex == <php> function is_uuid_regex($string) { return (bool)preg_match( '/^([0-9a-f]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12})$/S' ,$str...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

regex

<php> function is_uuid_regex($string) { return (bool)preg_match( '/^([0-9a-f]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12})$/S' ,$string); } </php>

no regex

<php> function is_uuid_no_regex($string) { $match = true; if(strlen($string) !== 36) { $match = false; } else if(strpos($string,'-') !== 8) { $match = false; } else if(ctype_alnum(str_replace('-',,$string)) === false) { $match = false; } else if(strpos($string,'-',24) !== false) { $match = false; } else if(strpos($string,'-',8) !== 8) { $match = false; } else if(strpos($string,'-',13) !== 13) { $match = false; } else if(strpos($string,'-',18) !== 18) { $match = false; } else if(strpos($string,'-',23) !== 23) { $match = false; } return $match; } </php>