UUID Regex Go Validator

Search...

⌘K

UUID Regex Go Validator

Search...

⌘K


UUID Regex Go Validator

UUID Regex Go Validator

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.

deadbeef-7331-4123-8123-ba5eba11babe
Possible security issues
This regex appears to be safe.
Explanation
  • [A-Z]: uppercase letters
  • [a-z]: lowercase letters
  • [0-9]: digits
  • \.: a literal dot
  • +: one or more of the preceding
  • *: zero or more of the preceding
  • ?: optional (zero or one)
  • ^: start of string
  • $: end of string
Match information
Match 1: "deadbeef-7331-4123-8123-ba5eba11babe" at index 0
Test your APIs today!

Write in plain English — Qodex turns it into secure, ready-to-run tests.

Regular Expression - Documentation

What is UUID Regex?


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-xxxxxxxxxxxx
  • x: 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


UUID Regex Pattern in Go


To validate UUIDs in Go using regex, you can use:


^[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


How to Validate UUIDs in Go


Here’s a working Go example:


package main

import (
    "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))
}


Use Cases


  • Assigning IDs in distributed databases

  • Identifying API users or sessions

  • Ensuring uniqueness in system logs or tokens

  • Referencing files, messages, or records across systems


Pro Tips for UUID Validation


  • 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.


Combine with These Tools


Create full mock data flows by combining this validator with:


Frequently asked questions

What’s the difference between UUID versions?×
Each version (1–5) is generated differently. For example, v1 uses time, v4 is random, and v5 is based on hashing.
Is UUID validation case-sensitive?+
Can UUIDs be generated without dashes?+
Why is regex used to validate UUIDs?+
Is UUID validation necessary?+