Skip to content

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:

  1. It should have 12 digits.
  2. It should not start with 0 and 1.
  3. It should not contain any alphabet and special characters.
  4. 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.

See also  Product of Array Except Self - Leetcode Challenge - Python Solution

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.