how to Validate Aadhaar Card Number in Javascript? – aadhaar card number validation

Today, We want to share with you aadhaar card number validation in javascript.In this post we will show you aadhar card validation in javascript, hear for adhaar number validation (verhoeff algorithm) we will give you demo and example for implement.In this post, we will learn about
10 digit mobile number validation using javascript
with an example.

how to Validate Aadhaar Card Number in Javascript?

first of all We Know that goverment Aadhaar Card has total 12-digits Numbers.
example like:

Aadhaar Card Number :

78XX 45XX 97XX
75XX 46XX 96XX
72XX 47XX 95XX
76XX 48XX 94XX

The valid Aadhar number must satisfy the bellow some conditions:

  1. Aadhaar Card has total 12 digits.
  2. not start with 0 & 1.
  3. not contain any alphabet & special characters.
  4. white space after every 4 digits.

REGULAR EXPRESSION

var regexp=/^[2-9]{1}[0-9]{3}\s{1}[0-9]{4}\s{1}[0-9]{4}$/;

12 or 16 Digit Aadhar Number Validation using JavaScript



12 digit Aadhaar Card Number validation in JavaScript

Yes, it is possible to validate an Aadhaar card number using JavaScript. Here’s an example function that checks whether an Aadhaar number is valid or not:

function validateAadhaar(aadhaar) {
  // The Aadhaar number must be 12 digits long
  if (aadhaar.length !== 12) {
    return false;
  }

  // The first digit must be between 1 and 9
  if (aadhaar.charAt(0) < '1' || aadhaar.charAt(0) > '9') {
    return false;
  }

  // The last digit must be a valid checksum
  var checkSum = 0;
  for (var i = 0; i < 11; i++) {
    var digit = parseInt(aadhaar.charAt(i));
    checkSum += (digit * (11 - i));
  }
  var lastDigit = (checkSum % 11);
  if (lastDigit !== 0 && lastDigit !== 1) {
    lastDigit = 11 - lastDigit;
  }
  return (lastDigit === parseInt(aadhaar.charAt(11)));
}

To use this function, you can pass an Aadhaar number as a string to the validateAadhaar function. The function will return true if the Aadhaar number is valid and false otherwise.

Here's an example usage:

var aadhaar = "123456789012";
if (validateAadhaar(aadhaar)) {
  console.log("Valid Aadhaar number");
} else {
  console.log("Invalid Aadhaar number");
}

Note: This function only checks the format of the Aadhaar number and its checksum, it does not verify whether the Aadhaar number is actually assigned to a particular individual or whether it is being used fraudulently.

I hope you get an idea about Aadhaar Card Number Validation Using Javascript.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment