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:
2017-05-09 14:36:44 +00:00
parent 92202f6af1
commit 3471cb3d4b
2 changed files with 75 additions and 0 deletions

View File

@@ -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;
}
}