Regex for Aadhaar Card Validation — 12-Digit Format and Edge Cases

Aadhaar is India's 12-digit unique identity number issued by UIDAI to over a billion residents. Because it is purely numeric, validating an Aadhaar field looks trivial at first glance — but real-world input includes spaces, hyphens, and leading digits that break naive checks. This guide covers the correct Aadhaar format, a solid regex pattern, and how to handle the formatting quirks you'll actually see in forms and CSV uploads.

Understanding the Aadhaar format

An Aadhaar number is exactly 12 digits with two structural rules that matter for validation:

  • It must be exactly 12 digits long — no letters, no more, no fewer.
  • The first digit is never 0 or 1. UIDAI only issues numbers starting from 2 through 9.
  • The last digit is a checksum computed using the Verhoeff algorithm, which regex cannot validate.

When displayed to users, Aadhaar numbers are usually formatted in three groups of four digits, such as 2345 6789 0123, but the underlying stored value should be the raw 12-digit string.

The Aadhaar regex pattern

^[2-9]{1}[0-9]{11}$

If you need to accept the space-grouped display format directly, use this variant, which allows optional single spaces between each group of four digits:

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

JavaScript example

function isValidAadhaar(aadhaar) {
  const cleaned = aadhaar.replace(/\s|-/g, "");
  const aadhaarRegex = /^[2-9]{1}[0-9]{11}$/;
  return aadhaarRegex.test(cleaned);
}

console.log(isValidAadhaar("2345 6789 0123")); // true
console.log(isValidAadhaar("1234-5678-9012")); // false - starts with 1
console.log(isValidAadhaar("234567890"));      // false - only 9 digits

Python example

import re

AADHAAR_REGEX = re.compile(r"^[2-9]{1}[0-9]{11}$")

def is_valid_aadhaar(value: str) -> bool:
    cleaned = re.sub(r"[\s-]", "", value)
    return bool(AADHAAR_REGEX.match(cleaned))

print(is_valid_aadhaar("2345 6789 0123"))  # True
print(is_valid_aadhaar("0345-6789-0123"))  # False - starts with 0

Why regex is not enough on its own

Regex validation is a good first filter, but treat it as necessary, not sufficient. Keep these limits in mind when handling Aadhaar data:

  • Regex cannot verify the Verhoeff checksum on the 12th digit — a random 12-digit string starting with 2-9 will pass the regex but may still be an invalid Aadhaar number.
  • Aadhaar data is sensitive personal information under Indian law. Mask it in logs and UI (show only the last 4 digits) and follow UIDAI's data-handling guidelines.
  • Never store raw Aadhaar numbers without encryption at rest if your application handles them at scale.

Frequently Asked Questions

What is the regex for validating an Aadhaar number?

A basic pattern is ^[2-9]{1}[0-9]{11}$. It requires exactly 12 digits where the first digit is between 2 and 9, since Aadhaar numbers never start with 0 or 1.

How do I handle Aadhaar numbers that include spaces?

Aadhaar numbers are often displayed in groups of four digits separated by spaces, like 2345 6789 0123. Strip all whitespace from the input with a replace step before running the 12-digit regex, or use a pattern that explicitly allows optional spaces between groups.

Does passing the regex mean the Aadhaar number is valid?

No. Regex only confirms the number has 12 digits and does not start with 0 or 1. Real Aadhaar numbers also satisfy a Verhoeff checksum algorithm on the last digit, which regex cannot compute — you need separate checksum logic or the official UIDAI verification API for that.

Try the Free AI Regex Generator

Need a regex for another Indian ID format or a custom validation rule? Describe it in plain English and get a tested pattern instantly with Dev Brains AI's free AI Regex Generator.

Related articles