Validate Aadhaar number in JavaScript
Aadhaar is a verifiable 12-digit identification number issued by UIDAI (Unique Identification Authority of India)to the resident of India for free of cost. It’s similar to the Social Security Numbers issued in the U.S.
An Aadhaar number should conform to the following rules:
- It should have 12 digits.
- It should not start with 0 and 1.
- It should not contain any alphabet and special characters.
- It should have white space after every 4 digits.
In JavaScript, to validate a number if it’s a valid Aadhaar number of not we match a regex and validate it.
function isValidAadhaar(aadhaar) { var regexp = /^[2-9]{1}[0-9]{3}\s{1}[0-9]{4}\s{1}[0-9]{4}$/; if (regexp.test(aadhaar)) { console.log("Valid Aadhaar"); return true; } else { console.log("Invalid Aadhaar"); return false; } }
As simple as that.