Aadhar Card Number Validation in Javascript

Spread the love

This article will teach the Aadhar Card Number Validation in Javascript. The Aadhaar card number is a unique 12-digit identification number issued by the Unique Identification Authority of India (UIDAI) to the people of India. It serves as proof of identity and address and is used for various government and non-governmental operations. The Aadhaar card includes biometric data such as fingerprints and iris scans, along with demographic information, making it a secure and widely accepted form of identification for citizens in India.

We are checking the following conditions to validate the Aadhar Card Number.

  1. It should have 12 digits.
  2. The first digit shouldn’t be either 0 or 1.
  3. It shouldn’t have any alphabet or special characters.
  4. We are NOT considering spaces between the digits during the validation process as those spaces will be handled at the client side application.

Aadhar Card Number Validation in Javascript

function validateAadhar(aadharNumber) {
  // Aadhar card number pattern
  const aadharPattern = /^[2-9]\d{11}$/;

  // Check if the Aadhar number matches the pattern and does not contain alphabet or special character
  if (aadharPattern.test(aadharNumber) && /^\d+$/.test(aadharNumber)) {
    return true; // Valid Aadhar number
  } else {
    return false; // Invalid Aadhar number
  }
}

// Example usage
const aadharNumberToValidate = '223456789012'; // Replace with the actual Aadhar number
if (validateAadhar(aadharNumberToValidate)) {
  console.log('Aadhar number is valid.');
} else {
  console.log('Aadhar number is invalid.');
}

In the above code, we have created a method called validateAadhar() which takes the number as an input and validates whether it is a valid Aadhar card number or not. To validate it, we are using regular expressions(REGEX) and we created a regular expression that matches the conditions mentioned above.

To check whether the number has alphabets or special characters, we are using a regular expression /^\d+$/ and to check the conditions, we are using the test() method which gives us the result that the given number is a valid Aadhar Card number or not.

This is how we can validate the Aadhar Card number using the Javascript.

Leave a Comment