REGEXVAULTv2.0
Identity & PII/Driver's License Numbers
Verified Safe

US Driver's License (Generic, State-Dependent) Regex for Go

/^[A-Z0-9]{1,2}[0-9]{1,18}$|^[A-Z][0-9]{3,8}[A-Z0-9]{0,3}$/i

What this pattern does

This page provides a well-structured, multi-part regular expression for matching us driver's license (generic, state-dependent), ported and verified for Go. Identity and credential patterns need both correctness and safety, since they're frequent targets for adversarial input. The snippet below is ready to drop into your Go project — whether you're validating in a Gin handler, a gRPC service, or a command-line tool.

Go Implementation

Go
// US Driver's License (Generic, State-Dependent)
// ReDoS-safe | RegexVault — Identity & PII > Driver's License Numbers

package validation

import "regexp"

var usDriversLicenseGenericStatedependentRe = regexp.MustCompile(`^[A-Z0-9]{1,2}[0-9]{1,18}$|^[A-Z][0-9]{3,8}[A-Z0-9]{0,3}$`)

func ValidateUsDriversLicenseGenericStatedependent(s string) bool {
    return usDriversLicenseGenericStatedependentRe.MatchString(s)
}

// Example
// fmt.Println(ValidateUsDriversLicenseGenericStatedependent("A12345678")) // true

Test Cases

Matches (Valid)
Rejects (Invalid)
A12345678ABCDEFGHIJKLMNOPQR
123456789!234567
A000000000
D1234567
A1

When to use this pattern

This pattern is drawn from the Identity & PII > Driver's License Numbers category and carries a ReDoS-safe certification. That matters for Go developers because Go's RE2 engine is inherently safe from catastrophic backtracking, but this pattern has been additionally verified for correctness. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

Without knowing the issuing state, US DL format validation is extremely permissive. Always capture the issuing state alongside the DL number. State DMV formats change over time without notice.

Technical Notes

US driver's license formats vary dramatically by state. California: 1 letter + 7 digits. Texas: 8 digits. New York: 9 digits or 1 letter + 18 digits. Florida: 1 letter + 12 digits. Use a state-specific library (e.g., driver-license-validator) for precise validation.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern