Change UUIdv4 validation to properly check for version 4 UUIDs

This commit is contained in:
Clemens Schwaighofer
2025-11-04 11:51:08 +09:00
parent c81b602657
commit 7d10b4c5af
2 changed files with 3 additions and 1 deletions

View File

@@ -56,6 +56,8 @@ print "UNIQU ID LONG : " . Uids::uniqIdLong() . "<br>";
$uuidv4 = Uids::uuidv4();
if (!Uids::validateUuuidv4($uuidv4)) {
print "Invalid UUIDv4: " . $uuidv4 . "<br>";
} else {
print "Valid UUIDv4: " . $uuidv4 . "<br>";
}
if (!Uids::validateUuuidv4("foobar")) {
print "Invalid UUIDv4: hard coded<Br>";

View File

@@ -81,7 +81,7 @@ class Uids
*/
public static function validateUuuidv4(string $uuidv4): bool
{
if (!preg_match("/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/", $uuidv4)) {
if (!preg_match("/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i", $uuidv4)) {
return false;
}
return true;