Posts tagged with “validation

Validating the format of a universally unique identifier

Here’s a function to validate the format of a universally unique identifier, or UUID: function uuid_is_valid( $uuid ) { // check string length if( strlen( $uuid ) != 36 ) return false; // no good // check formatting return preg_match( ‘/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89AB][0-9a-f]{3}-[0-9a-f]{12}$/i’, $uuid ) ? true : false; } It’s expecting a 36-character UUID. Adjust this […]