-
-
Save vip3r011/1f1e51304c5858f9d371acd3293e0b40 to your computer and use it in GitHub Desktop.
Check if UUID is in valid format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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