Skip to content

Instantly share code, notes, and snippets.

@vip3r011
Forked from Joel-James/verify-uuid.php
Created May 23, 2018 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vip3r011/1f1e51304c5858f9d371acd3293e0b40 to your computer and use it in GitHub Desktop.
Save vip3r011/1f1e51304c5858f9d371acd3293e0b40 to your computer and use it in GitHub Desktop.
Check if UUID is in valid format
<?php
/**
* Check if a given string is a valid UUID
*
* @param string $uuid The string to check
* @return boolean
*/
function isValidUuid( $uuid ) {
if (!is_string($uuid) || (preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/', $uuid) !== 1)) {
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment