-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[6.x] Add Str::isUuid() helper (#31148)
* Add Str::isUuid() helper * Style CI Fix * Update Str.php Co-authored-by: Taylor Otwell <taylor@laravel.com>
- Loading branch information
1 parent
f9c450a
commit bfd17f0
Showing
3 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -251,6 +251,21 @@ public static function is($pattern, $value) | |
return false; | ||
} | ||
|
||
/** | ||
* Determine if a given string is a valid UUID. | ||
* | ||
* @param string $value | ||
* @return bool | ||
*/ | ||
public static function isUuid($value) | ||
{ | ||
if (! is_string($value)) { | ||
return false; | ||
} | ||
|
||
return preg_match('/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iD', $value) > 0; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
GrahamCampbell
Member
|
||
} | ||
|
||
/** | ||
* Convert a string to kebab case. | ||
* | ||
|
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
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
The Lib (Ramsey\Uuid\Uuid) that we use to generate Uuid has a validator method:
Ramsey\Uuid\Uuid::isValid($uuid);
The REGEX used in lib is:
'^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$'