Regex for Aadhaar number (12 digits)

An Aadhaar number has 12 digits, usually written in three groups of four with spaces. The first digit is never 0 or 1. This pattern accepts both the spaced and the unspaced form.

The pattern

/\b[2-9]\d{3}\s?\d{4}\s?\d{4}\b/g

The tester opens with this pattern and the examples below already loaded. Nothing you type is uploaded.

How it works

\b
Word boundary at both ends so longer digit strings do not match.
[2-9]
First digit, 2 to 9 (Aadhaar numbers do not start with 0 or 1).
\d{3}
Remaining three digits of the first group.
\s?
An optional space between groups.
\d{4}
Second and third groups of four digits each.

Examples

Matches

  • 2345 6789 0123
  • 234567890123
  • 9876 5432 1098

Does not match

  • 0123 4567 8901
  • 1234 5678 9012
  • 2345 6789 012

Use it in JavaScript

const re = /\b[2-9]\d{3}\s?\d{4}\s?\d{4}\b/g;

// Find every match in a block of text
const found = text.match(re);

// Validate that a whole value matches (no stray characters around it)
const exact = new RegExp('^(?:' + re.source + ')$', re.flags.replace('g', ''));
const isValid = exact.test(value);

Limits and tips

  • The last digit of an Aadhaar number is a Verhoeff checksum. A regex cannot calculate it, so run a checksum function if you need to reject mistyped numbers.
  • Aadhaar numbers are sensitive personal data. Test with made-up numbers, and collect or store full numbers only where the law and your use case require it.
  • The \s? allows one whitespace character. To also accept a dash, change it to [\s-]?.

Frequently asked questions

Can an Aadhaar number start with 0 or 1?

No. The first digit is between 2 and 9, which is why the pattern starts with [2-9].

How do I validate the Aadhaar checksum?

Use the Verhoeff algorithm in code after the regex check. A regular expression cannot compute it.