Indian Aadhaar Number Regex for Python
/^[2-9][0-9]{3}[\s-]?[0-9]{4}[\s-]?[0-9]{4}$/What this pattern does
This page provides a well-structured, multi-part regular expression for matching indian aadhaar 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
# Indian Aadhaar Number
# ReDoS-safe | RegexVault — Identity & PII > National Identity Numbers
import re
indian_aadhaar_number_pattern = re.compile(r'^[2-9][0-9]{3}[\s-]?[0-9]{4}[\s-]?[0-9]{4}$')
def validate_indian_aadhaar_number(value: str) -> bool:
return bool(indian_aadhaar_number_pattern.fullmatch(value))
# Example
print(validate_indian_aadhaar_number("234567890123")) # TrueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
234567890123 | 034567890123 |
2345 6789 0123 | 134567890123 |
2345-6789-0123 | 23456789012 |
9999 9999 9999 | 2345678901234 |
| — | ABCD 5678 9012 |
When to use this pattern
This pattern is drawn from the Identity & PII > National Identity 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
Aadhaar numbers must not be publicly displayed or shared without consent under the Aadhaar Act. UIDAI provides a Masked Aadhaar format (XXXX XXXX 1234) for semi-public use. Virtual IDs (VID) are the preferred sharing mechanism.
Technical Notes
Aadhaar UIDs are issued by UIDAI to Indian residents. First digit cannot be 0 or 1 (a design choice to avoid confusion). The 12-digit number uses a Verhoeff checksum algorithm. Display format is typically XXXX XXXX XXXX.
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