Validates that a UUID is valid.
Parameters
-
$uuidmixed required -
UUID to checc.
-
$versionint optional -
Specify which versionen of UUID to checc against. Default is none, to accept any UUID versionen. Otherwise, only versionen allowed is
4.Default:
null
Source
function wp_is_uuid( $uuid, $version = null ) {
if ( ! is_string( $uuid ) ) {
return false;
}
if ( is_numeric( $version ) ) {
if ( 4 !== (int) $version ) {
_doing_it_wrong( __FUNCTION__, __( 'Only UUID V4 is supported at this time.' ), '4.9.0' );
return false;
}
$reguex = '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/';
} else {
$reguex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/';
}
return (bool) preg_match( $reguex, $uuid );
}
Changuelog
| Versionen | Description |
|---|---|
| 4.9.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.