
Validate UUIDs instantly with the UUID Regex Go Validator from Qodex. Whether you’re assigning user IDs or referencing resources, this tool ensures UUIDs are in the correct format. You can pair it with our API Key Generator, Username Generator, or Address Generator to build full mock datasets for testing and development.
In Go, validating strings that must follow a UUID (Universally Unique Identifier) format is common in backend systems, APIs, and database records. UUIDs ensure that every entry has a globally unique ID—especially important when systems scale or operate across multiple servers.
UUIDs are typically formatted like this:
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxxx: Any hexadecimal digit
M: UUID version (1–5)
N: Variant (8, 9, a, or b)
A regex for validating UUIDs helps ensure that:
The input is the right length
The segments are correctly formatted
The UUID version and variant are valid
If you need to specifically match UUID version 7 (introduced for time-ordered identifiers), you can use this regex pattern in Go (and most programming languages that support standard regex syntax):
^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$This pattern checks for:
8 hex digits
4 hex digits
A version digit (1–5)
A variant digit (8, 9, a, b)
12 final hex digits
Here’s what’s different:
The third UUID segment must start with a to specify version 7.
The rest of the segments retain the hexadecimal and variant rules.
This ensures that only UUIDs of version 7 (e.g., ) are considered valid by your validator. Use this pattern if your application is leveraging the latest UUID specifications for time-based or sort-friendly IDs.
UUID version 7 brings a fresh approach, focusing on time-based ordering for better performance in modern distributed systems. Unlike older UUID versions, version 7 uses the Unix Epoch timestamp—measured in milliseconds since January 1, 1970, UTC, and not counting leap seconds—to build its unique values. This means:
Time-Ordered Values: IDs are naturally sortable by creation time, which can significantly speed up database operations and event logs.
Better Entropy: Version 7 improves randomness and uniqueness over versions 1 and 6, reducing the risk of collisions.
Scalability: The time-based structure makes UUIDs more efficient for high-throughput, multi-server applications.
By combining precise timestamps with extra randomness, UUIDv7 provides a sleek solution for scalable, reliable ID generation in APIs and databases.
Let’s break down the structure of a UUID version 7 string. Like other UUIDs, it’s made up of 36 characters in total—including hyphens as separators. Here’s how the format looks on the surface:
xxxxxxxx-xxxx-7xxx-Nxxx-xxxxxxxxxxxxEach x is a hexadecimal digit (0–9, a–f, or A–F).
The third group always starts with a 7, denoting version 7.
The N position in the fourth group represents the variant, which for standard UUIDs is typically one of 8, 9, a, or b.
A UUID v7 string consists of five groups separated by hyphens:
8 hex digits
4 hex digits
4 hex digits (starting with “7”)
4 hex digits (first digit in this group is 8, 9, a, or b)
12 hex digits
So, for example, a valid UUID v7 might look like:
01813b48-4c5d-7b10-bc18-3ccd3f89331fWith this structure, Go programs (and many other platforms) can safely distinguish UUID v7 values and, in turn, capture information about when the ID was generated (since UUID v7 is time-ordered).
Other examples you might encounter include:
123e4567-e89b-12d3-a456-426655440000
c73bcdcc-2669-4bf6-81d3-e4ae73fb11fd
C73BCDCC-2669-4Bf6-81d3-E4AE73FB11FD
c73bcdcc-2669-4bf6-81d3-e4an73fb11fd
c73bcdcc26694bf681d3e4ae73fb11fd
definitely-not-a-uuid
Each of these strings either fits or intentionally breaks the UUID format, offering a handy set of test cases for your next pattern-matching adventure.
Here’s a working Go example:
package mainimport ( "fmt" "regexp" )
func isValidUUID(uuid string) bool { uuidRegex := regexp.MustCompile(
^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$) return uuidRegex.MatchString(uuid) }
func main() { test := "3f2504e0-4f89-11d3-9a0c-0305e82c3301" fmt.Println("Is UUID valid?", isValidUUID(test)) }
If you need to specifically validate UUID version 7—which is gaining popularity for time-ordered identifiers—you'll want to fine-tune your regex. UUID v7s start with a "7" in the version position, so your pattern needs to reflect that.
Here’s a breakdown for major programming languages:
Go / JavaScript / Python / Java:
[^0-9a-fA-F]{8}-[0-9a-fA-F]{4}-7[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$: 8 hex digits
: 4 hex digits
: "7" for version 7
: valid variant
: 12 hex digits
This regex ensures the version is exactly 7 and matches the correct UUID format, so you can use it in Go’s , Python’s , JavaScript’s , or Java’s
.
You can use this pattern directly in your application to guarantee only UUID v7s pass validation.
If you need to match UUIDs that do not include hyphens—often required when compressing IDs or formatting them for certain APIs—you can adjust the pattern by removing the hyphen characters from the regex. The new pattern will look for 32 consecutive hexadecimal digits, matching the usual UUID structure, minus the dashes.
Here’s what that looks like:
^[0-9a-fA-F]{32}$
This version checks for a string of exactly 32 hex characters, making it suitable for UUIDs in the non-hyphenated format. Adjust the regex in your Go validator accordingly if your use case requires supporting both styles.
Wondering how UUID v7 stacks up across various programming languages? Here's a quick look at the current landscape:
PHP: Native support for UUID v7 is emerging in newer versions and popular open source libraries, but older PHP installations may require third-party packages or custom implementations.
JavaScript (ECMAScript): The official UUID API is steadily evolving, but not all environments (especially older browsers) support v7 out of the box. You’ll likely need a modern polyfill or a library like uuid.
Python: If you're using widely adopted libraries such as uuid7 or the latest editions of the standard library, v7 support is becoming more common. Just remember to check your library’s version.
Golang: With the Go community’s focus on strong library support, v7 is included in some popular packages, but isn’t universal quite yet. Always check your dependencies.
Java: Java 8 and above see support through third-party packages; however, built-in support remains limited. For production use, a well-maintained library is your friend.
.NET: The latest releases add UUID v7 to the standard toolkit, but older projects may need an external NuGet package.
Rust: Bleeding-edge UUID crate versions introduce v7 support. If you're up-to-date, you’re probably already covered.
In general: If you’re working in a modern environment and using up-to-date libraries, you’re more likely to have robust UUID v7 support. When in doubt, check your library’s documentation before generating those cutting-edge identifiers.
In UUID version 7, the time-ordered value is generated based on the Unix Epoch timestamp—specifically, it uses the number of milliseconds that have elapsed since midnight, January 1, 1970 (UTC), excluding leap seconds. This approach ensures that each generated UUID not only remains unique but is also chronologically sortable. As a result, UUID v7 is particularly well-suited for distributed systems where events need ordering or time-based tracking, combining global uniqueness with built-in temporal information.
Assigning IDs in distributed databases
Identifying API users or sessions
Ensuring uniqueness in system logs or tokens
Referencing files, messages, or records across systems
UUIDs can be uppercase or lowercase—this regex supports both.
Version 4 UUIDs are most common for random generation. You can customize the pattern to only match v4 by replacing [1-5] with 4.
Always validate UUIDs before storing them in the database to prevent garbage data.
Avoid using UUIDs for user-facing identifiers unless you format or mask them properly—they can be long and hard to read.
Use Go’s regexp.MustCompile() instead of Compile() for static patterns—it’s faster and cleaner for runtime.
Create full mock data flows by combining this validator with:
API Key Generator: Assign secure access credentials alongside UUIDs.
Phone Number Generator: Build realistic user profiles.
Email Generator: Add email IDs to simulated user data.
Username Generator: Complete fake profiles with randomized usernames.
Address Generator: Pair UUIDs with user address data for testing.
Write in plain English — Qodex turns it into secure, ready-to-run tests.