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

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

/^[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 JavaScript. 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 JavaScript project — whether you're validating in an Express middleware, a Next.js API route, or a client-side form.

Javascript Implementation

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

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

function validateUsDriversLicenseGenericStatedependent(input: string): boolean {
  return usDriversLicenseGenericStatedependentRegex.test(input);
}

// Example
console.log(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 JavaScript developers because especially critical in long-running Node.js event loops where a ReDoS vulnerability can block the entire process. 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