/^/
EasyInternational4 min read

Aadhaar Number Regex

Validates the format of an Indian Aadhaar 12-digit identity number, accepting either the compact digit-only form or the conventional space-grouped form like 1234 5678 9012.

#aadhaar#india#identity#validation#international#national-id

Regex Pattern

^[2-9]\d{3}\s?\d{4}\s?\d{4}$

Pattern Breakdown

Hover over a token to see what it does.

^[2-9]\d{3}\s?\d{4}\s?\d{4}$
TokenMeaning
^Anchors the match to the start of the string
[2-9]First digit must be 2-9; Aadhaar numbers never start with 0 or 1
\d{3}Three more digits completing the first 4-digit group
\s?An optional single whitespace character (used as the conventional group separator)
\d{4}The second group of four digits
$Anchors the match to the end of the string

Detailed Explanation

What it does

This pattern validates that a string is 12 digits long, does not start with 0 or 1, and is either written as one contiguous run of digits or grouped into three sets of four separated by single spaces, matching how Aadhaar numbers are printed on the physical card.

Why it works

UIDAI never issues Aadhaar numbers starting with 0 or 1, so the leading `[2-9]` rules out an entire class of invalid input immediately. Making each `\s?` independently optional lets the same pattern accept both the raw 12-digit form used by APIs and the human-readable spaced form used on cards, without requiring two separate patterns.

Common use cases

  • Validating Aadhaar input fields on Indian government or fintech onboarding forms
  • Normalizing user-entered Aadhaar numbers before stripping spaces and storing them
  • Client-side sanity checks before submitting to an Aadhaar verification/OTP API
  • Detecting Aadhaar-shaped strings in documents for redaction or masking

Edge cases

  • Because each space is independently optional, mixed spacing like '2345 67890123' still matches, which may be looser than desired
  • Tab or newline characters also satisfy \s and would be accepted as separators, not just a literal space
  • A structurally valid 12-digit number is not guaranteed to be a real, issued Aadhaar number
  • Numbers with hyphens instead of spaces, like '2345-6789-0123', are correctly rejected

Limitations

  • Does not implement the Verhoeff checksum algorithm that UIDAI uses to validate the last digit
  • Cannot confirm the number was actually issued or belongs to a real individual
  • Does not restrict separators to exactly zero or exactly two spaces (all-or-nothing)
  • Real verification requires UIDAI's official demographic or OTP-based authentication APIs

Interactive Tester

Edit the pattern or text below — matching runs live in your browser.

2345 6789 0123 234567890123 9876 5432 1098

Test Cases

Editable — add your own inputs to see if they pass.

InputExpectedResult
Pass
Pass
Pass
Pass
Pass
Pass
Pass
Pass

Language Variants

Production-ready examples in 12 languages.

const aadhaarRegex = /^[2-9]\d{3}\s?\d{4}\s?\d{4}$/;
console.log(aadhaarRegex.test('2345 6789 0123')); // true

Common Mistakes

Requiring spaces to be either fully present or fully absent using a single optional group

Fix: If strict formatting matters, use an alternation like ^(?:\d{12}|\d{4} \d{4} \d{4})$ instead of independently optional spaces

Treating a format-valid Aadhaar as verified identity proof

Fix: Use UIDAI's official verification or OTP-based eKYC APIs for real authentication

Storing Aadhaar numbers in plaintext after validation

Fix: Aadhaar is sensitive PII in India; mask, encrypt, or tokenize it per UIDAI data-handling guidelines

Performance Notes

  • Fixed-width digit groups with optional single-character separators keep matching linear with no backtracking risk
  • The leading [2-9] check fails fast on the ~20% of random 12-digit strings that start with 0 or 1
  • Strip whitespace before storage/comparison so downstream lookups don't need to re-run the spaced-format regex

Browser Compatibility

EngineSupportedNotes
ChromeYes
FirefoxYes
SafariYes
EdgeYes
Node.jsYes