Indian Aadhaar Number Regex for PHP
/^[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 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
// Indian Aadhaar Number
// ReDoS-safe | RegexVault — Identity & PII > National Identity Numbers
define('INDIAN_AADHAAR_NUMBER_PATTERN', '/^[2-9][0-9]{3}[\s-]?[0-9]{4}[\s-]?[0-9]{4}$/');
function validate_indian_aadhaar_number(string $input): bool {
return (bool) preg_match(INDIAN_AADHAAR_NUMBER_PATTERN, $input);
}
// Example
var_dump(validate_indian_aadhaar_number("234567890123")); // bool(true)Test 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 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
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