US Driver's License (Generic, State-Dependent) Regex for PHP
/^[A-Z0-9]{1,2}[0-9]{1,18}$|^[A-Z][0-9]{3,8}[A-Z0-9]{0,3}$/iWhat 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 PHP. 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 PHP project — whether you're validating in a Laravel validator, a WordPress plugin, or a standalone PHP script.
Php Implementation
<?php
// US Driver's License (Generic, State-Dependent)
// ReDoS-safe | RegexVault — Identity & PII > Driver's License Numbers
define('US_DRIVERS_LICENSE_GENERIC_STATEDEPENDENT_PATTERN', '/^[A-Z0-9]{1,2}[0-9]{1,18}$|^[A-Z][0-9]{3,8}[A-Z0-9]{0,3}$/');
function validate_us_drivers_license_generic_statedependent(string $input): bool {
return (bool) preg_match(US_DRIVERS_LICENSE_GENERIC_STATEDEPENDENT_PATTERN, $input);
}
// Example
var_dump(validate_us_drivers_license_generic_statedependent("A12345678")); // bool(true)Test Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
A12345678 | ABCDEFGHIJKLMNOPQR |
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 PHP developers because especially relevant in PHP where PCRE backtracking limits can trigger silent failures on malicious input. 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