Indian Aadhaar Number Regex for Go
/^[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 Go. 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 Go project — whether you're validating in a Gin handler, a gRPC service, or a command-line tool.
Go Implementation
// Indian Aadhaar Number
// ReDoS-safe | RegexVault — Identity & PII > National Identity Numbers
package validation
import "regexp"
var indianAadhaarNumberRe = regexp.MustCompile(`^[2-9][0-9]{3}[\s-]?[0-9]{4}[\s-]?[0-9]{4}$`)
func ValidateIndianAadhaarNumber(s string) bool {
return indianAadhaarNumberRe.MatchString(s)
}
// Example
// fmt.Println(ValidateIndianAadhaarNumber("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 Go developers because Go's RE2 engine is inherently safe from catastrophic backtracking, but this pattern has been additionally verified for correctness. 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