* @license http://opensource.org/licenses/MIT MIT */ declare(strict_types=1); namespace Ramsey\Uuid\Validator; use Ramsey\Uuid\Uuid; /** * Validator validates strings as UUIDs of any variant */ class Validator implements ValidatorInterface { /** * Regular expression pattern for matching a UUID of any variant. */ public const VALID_PATTERN = '^[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}$'; public function validate(string $uuid): bool { $uuid = str_replace(['urn:', 'uuid:', 'URN:', 'UUID:', '{', '}'], '', $uuid); return $uuid === Uuid::NIL || preg_match('/' . self::VALID_PATTERN . '/D', $uuid); } }