Aadhaar
Validates an Aadhaar number: exactly 12 digits, first digit 2–9, and the last digit must satisfy the Verhoeff checksum — the same check UIDAI uses. Spaces and dashes are ignored, so 2345 6789 0124 validates the same as 234567890124.
| Rule | Detail |
|---|---|
| Length | Exactly 12 digits |
| First digit | 2–9 (Aadhaar never starts with 0 or 1) |
| Characters | Digits only, ignoring spaces and - |
| Checksum | Verhoeff — catches every single-digit typo and most transpositions |
import { validateAadhaar } from 'indycheck';
validateAadhaar('234567890124');// { ok: true, code: 'VALID', normalized: '234567890124',// parsed: { masked: 'XXXX XXXX 0124' } }
validateAadhaar('2345 6789 0124'); // ok: true — spaces ignoredvalidateAadhaar('234567890123'); // ok: false, code: 'INVALID_CHECKSUM'from indycheck import validate_aadhaar
r = validate_aadhaar("234567890124")print(r.parsed["masked"]) # XXXX XXXX 0124use indycheck::validate_aadhaar;
let r = validate_aadhaar("234567890124");assert!(r.ok);Examples
Section titled “Examples”| Input | Result | Code |
|---|---|---|
234567890124 |
Valid (Verhoeff passes) | VALID |
871366569991 |
Valid | VALID |
2345 6789 0124 |
Valid (spaces ignored) | VALID |
234567890123 |
Invalid — checksum fails | INVALID_CHECKSUM |
123456789012 |
Invalid — starts with 1 | INVALID_FIRST_DIGIT |
23456789012 |
Invalid — 11 digits | INVALID_LENGTH |
23456789012A |
Invalid — letter inside | INVALID_FORMAT |
| (empty) | Invalid | EMPTY |
Error codes
Section titled “Error codes”| Code | Means |
|---|---|
EMPTY |
Nothing was passed in |
INVALID_FORMAT |
Non-digit characters (other than spaces / -) |
INVALID_LENGTH |
Not exactly 12 digits |
INVALID_FIRST_DIGIT |
First digit is 0 or 1 |
INVALID_CHECKSUM |
Verhoeff checksum failed — mistyped or fake number |
Parsed output
Section titled “Parsed output”On success, parsed contains:
{ "masked": "XXXX XXXX 0124" }Use the masked value everywhere — in logs, in your database, in API responses. You almost never need the full number after validation.