How to Validate a UUID

A valid UUID (RFC 4122) has the form xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx: 32 hex digits in five groups separated by hyphens. M is the version nibble (1–5, 7, or 0 for nil); N is the variant nibble (8, 9, A, or B). Here's how to validate.

Regex

A simple pattern for standard UUIDs (versions 1–5, 7, and nil) is:

/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5]|[7]|[0][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i

Strip spaces and normalize to lowercase before matching if you accept input with or without hyphens; you can then re-format to canonical form.

Online and API

Use our validator to paste a string and see if it's valid, plus the detected version and variant. For automation, call GET /api/validate/{uuid} for a single check or POST /api/validate-bulk with a JSON array of strings (max 1000) to validate many at once. Responses include uuid, status (valid/invalid), and type (version or null).

In Code

Most languages have a built-in or library check (e.g. uuid.UUID in Python, UUID.parse in Java). Validate before storing or sending; reject or normalize invalid input to avoid bad data. For bulk validation, use our API or implement the regex above in your stack.

Try the validator · UUID in Python · UUID in JavaScript