A UUID turns up in a log file, an API response or a bug report, and you need to know one thing before you trust it: is this a UUID, or a truncated, mistyped string that looks like one? A malformed identifier fails quietly: a database lookup returns nothing, a join misses, and the real cause, one missing digit, hides in plain sight.
This guide teaches you to validate a UUID format yourself. One honesty note first: the UUID Generator on Ovatly does not have a validate mode. It generates version 4 UUIDs, and that is all it does. Validation is a check you perform on a value you already have, by eye, or with a regex for batches.
Contents
- Quick answer
- The anatomy of a valid UUID
- The two marker positions that identify version 4
- How to validate a UUID, step by step
- Worked example: one good value, three bad ones
- Limitations: what a format check cannot tell you
- Common mistakes
- FAQs
- Conclusion
Quick answer
A valid UUID is 32 hexadecimal digits in five hyphen-separated groups of 8, 4, 4, 4 and 12, 36 characters with hyphens. Check length and groups first, then confirm every character is a digit or a letter from a to f. For a version 4 value, two positions are fixed: the third group starts with 4, and the fourth group starts with 8, 9, a or b. In code, the version 4 check is one regex: /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.
The anatomy of a valid UUID
A UUID is a 128-bit identifier written as 32 hexadecimal digits grouped by hyphens. Each character is hexadecimal: a digit 0 to 9 or a letter from a to f. Any other letter, g through z, disqualifies the string at once, as does any punctuation other than the four hyphens.
The group lengths are the part people get wrong, because they are not even: 8, then 4, 4, 4, then 12. Add the four hyphens and a complete UUID is always exactly 36 characters long. That fact alone catches a large share of bad values: at 35 or 37 characters, something was dropped or added.
Case is the one flexible point. Hexadecimal digits can be upper or lower case; both forms represent the same value. The canonical form, the one the generator returns and most databases and APIs expect, is lowercase with hyphens. A validator should accept either case, then normalise to lowercase before the value is stored or compared.
The two marker positions that identify version 4
Not every digit in a UUID is free to be anything: two positions in the pattern xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx are fixed markers rather than random digits.
The first marker is the opening digit of the third group. It records the version: how the value was produced. A 4 there means version 4, the random kind, which is what the UUID Generator creates. Other digits mean other versions, and a letter there means the string was never a generated UUID at all.
The second marker is the opening digit of the fourth group, the y position in the pattern. On a standard value it is always one of 8, 9, a or b. That narrow set marks the variant. If that position holds any other character, the string may be a 36-character code of some kind, but it is not following the UUID layout.
The two markers also explain a number worth knowing: of the 128 bits in a version 4 UUID, 122 are random, and the rest are spent on these fixed positions. Validating means checking the fixed bits are where they belong and the remaining bits are written in legal characters.
How to validate a UUID, step by step
- Count the characters. A complete UUID is 36 characters: 32 hexadecimal digits and 4 hyphens. Any other length fails immediately.
- Check the groups. Split on the hyphens: five groups of 8, 4, 4, 4 and 12. A missing hyphen merges two groups and fails this check.
- Check the alphabet. Every character must be a digit or one of a to f, in either case. One stray letter outside that set fails the value.
- Check the markers. The third group must start with 4 for a version 4 value, and the fourth group must start with 8, 9, a or b.
- Or run the regex. For batches, use
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, which encodes all the checks above; the trailingiaccepts upper and lower case. - Get a known-good specimen to test against. Open the UUID Generator, generate one value, and run your checker on it. A validator that rejects a freshly generated UUID has a bug.
Worked example: one good value, three bad ones
Here is a freshly generated version 4 UUID to practise on: 91ade740-0c05-4adb-ae9c-42cd9ec77873. Walk the checks: 36 characters; groups of 8, 4, 4, 4, 12; every character a digit or a letter from a to f; the third group, 4adb, starts with 4; the fourth group, ae9c, starts with a, in the allowed set. The regex returns a match. It passes every check.
Now three failures, each broken in exactly one way. 550e8400-e29b-51d4-a716-446655440000 has the right length and legal characters, but its third group starts with 5, so it is not a version 4 value. 550e8400-e29b-41d4-c716-446655440000 gets the version digit right, but the fourth group starts with c, outside the allowed set, so the variant marker is wrong. 550e8400-e29b-41d4-a716-44665544000 is the quietest failure: every marker is correct, but the last group has 11 digits instead of 12 and the total length is 35, so the first check already rejects it. The classic copy-and-paste truncation, which is why the length check comes first.
Limitations: what a format check cannot tell you
Validation proves shape, nothing more. A string can pass every check and still be a value someone typed by hand, a placeholder pasted from documentation, or a duplicate of an identifier in use elsewhere: the check reads characters, not history.
It also cannot tell you how the value was generated. The uniqueness of a version 4 UUID rests on its 122 random bits coming from a cryptographic random source, which is how the generator on this page produces them. A value built from a weak random source, or assembled by hand to look right, passes format validation just as well as a properly generated one. If provenance matters, validate the generator, not just the string.
Common mistakes
- Checking the length but not the groups. A 36-character string with a hyphen in the wrong place has merged or split groups and is not a valid UUID, however right the total looks.
- Forgetting the variant marker. Many quick checks test only the version digit. The fourth group opening, one of 8, 9, a or b, is half of what makes the value a standard version 4 UUID.
- Rejecting uppercase values. Uppercase hexadecimal is the same value in a different spelling. Accept it, normalise it to canonical lowercase, and move on.
- Treating a passed check as proof of uniqueness. Format validation says the string is shaped like a UUID. It says nothing about duplicates, which are a property of how the value was generated.
FAQs
Does the UUID Generator have a validate mode? No. The tool generates version 4 UUIDs, from 1 to 100 at a time, and nothing else. Validation is a format check you perform on a value you already have, by eye or with a regex, using the group lengths and the two fixed marker positions.
What makes a UUID format valid? A valid UUID is 32 hexadecimal digits arranged in five groups of 8, 4, 4, 4 and 12, separated by hyphens, for 36 characters in total. Every character must be a digit or one of the letters a to f, in either case.
How can I tell if a UUID is version 4? Look at two positions. The first digit of the third group is the version marker: 4 means version 4. The first digit of the fourth group is the variant marker, and on a standard version 4 value it is one of 8, 9, a or b.
Is an uppercase UUID still valid? Yes, as a format. Hexadecimal digits can be written in either case and the value is the same. The canonical form, and the form the generator returns, is lowercase with hyphens, which is what most databases and APIs expect, so normalise to lowercase before storing or comparing.
Does a valid format mean the UUID is unique or genuine? No. A format check confirms only that the string is shaped like a UUID. It cannot tell you who generated it, whether it was random, or whether the same value exists somewhere else. Uniqueness comes from how the value was generated, not from its shape.
Conclusion
Validating a UUID is a thirty-second skill once the pattern is in your head: 36 characters, groups of 8-4-4-4-12, hexadecimal characters only, a 4 opening the third group and one of 8, 9, a or b opening the fourth. Do it by eye for a single value, keep the regex for batches, and test your checker against a fresh value from the UUID Generator before trusting it. The natural next question is why random values from such a simple shape practically never repeat. That is the subject of the companion guide, Can Two UUIDs Ever Be the Same? Collision Risk Explained.
More tools for this kind of work live in the Developer Tools archive.