UK DVLA Driver's License Number Regex for Python
/^[A-Z9]{5}[0-9]{6}[A-Z9]{2}[A-Z0-9]{2}[A-Z]{1,2}[0-9]$/iWhat this pattern does
This page provides a well-structured, multi-part regular expression for matching uk dvla driver's license number, ported and verified for Python. 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 Python project — whether you're validating in a Django view, a FastAPI endpoint, or a standalone data processing script.
Python Implementation
# UK DVLA Driver's License Number
# ReDoS-safe | RegexVault — Identity & PII > Driver's License Numbers
import re
uk_dvla_drivers_license_number_pattern = re.compile(r'^[A-Z9]{5}[0-9]{6}[A-Z9]{2}[A-Z0-9]{2}[A-Z]{1,2}[0-9]$')
def validate_uk_dvla_drivers_license_number(value: str) -> bool:
return bool(uk_dvla_drivers_license_number_pattern.fullmatch(value))
# Example
print(validate_uk_dvla_drivers_license_number("SMITH691203A99AB5")) # TrueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
SMITH691203A99AB5 | MORGA65705SM9IJ |
JONES701215D99CD3 | morga657054sm9ij |
| — | MORGA657054SM9I |
| — | M0RGA657054SM9IJ |
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 Python developers because particularly important in Python web servers where CPU-bound regex operations can stall concurrent request handling. 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
UK driving licence numbers encode personal data by design. A change of name (e.g., after marriage) requires a new licence with a new number. The encoded gender is binary — the DVLA is updating this for non-binary licence holders.
Technical Notes
UK DL structure: surname (first 5 chars, padded with 9), birth decade digit + DOB (MDDYM where M is month, padded for females with 5 added to month), initials + suffix digits. Encodes surname, DOB, and gender — extremely information-dense PII.
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