verify: add the verification of UUID
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3624 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
33
verify.php
33
verify.php
@@ -285,4 +285,37 @@ class verify
|
||||
{
|
||||
return !! filter_var ($val, FILTER_VALIDATE_URL);
|
||||
}
|
||||
|
||||
//////////////////
|
||||
/// OTHERS ///
|
||||
//////////////////
|
||||
/** Return true if the provided value is a valid UUID
|
||||
* %04x%04x-%04x-%04x-%04x-%04x%04x%04x
|
||||
* @param string $val The value to check
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_UUID ($val)
|
||||
{
|
||||
return \verify::staticIs_UUID ($val);
|
||||
}
|
||||
|
||||
/** Return true if the provided value is a valid UUID in static mode
|
||||
* %04x%04x-%04x-%04x-%04x-%04x%04x%04x
|
||||
* @param string $val The value to check
|
||||
* @return boolean
|
||||
*/
|
||||
public static function staticIs_UUID ($val)
|
||||
{
|
||||
if (! is_string ($val))
|
||||
return false;
|
||||
if (strlen ($val) !== 36)
|
||||
return false;
|
||||
if (strspn ($val, "0123456789abcdefABCDEF-") !== strlen ($val))
|
||||
return false;
|
||||
if ($val[8] !== "-" || $val[13] !== "-" || $val[18] !== "-" ||
|
||||
$val[23] !== "-")
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user