15,849,197 members
See more:
I am going to validate the given aadhaar number in valid one or invalid this only i don't need the other details, like the validation might be used for some algorithm that's what i asking..!

What I have tried:

I am going to validate the given aadhaar number in valid one or invalid this only i don't need the other details, like the validation might be used for some algorithm that's what i asking..!
Posted
Updated 29-Oct-20 8:08am
v2

## Solution 1

Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...

A very quick search gave over 350,000 results: aadhaar number validation php - Google Search[^]

In future, please try to do at least basic research yourself, and not waste your time or ours.

vengateshwaran 4-Jan-18 8:04am
function checkUID(e) {
/*e.preventDefault();*/
/*console.log(uid);*/
if (uid.length != 12) {
return false;
}

var Verhoeff = {
"d": [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 2, 3, 4, 0, 6, 7, 8, 9, 5],
[2, 3, 4, 0, 1, 7, 8, 9, 5, 6],
[3, 4, 0, 1, 2, 8, 9, 5, 6, 7],
[4, 0, 1, 2, 3, 9, 5, 6, 7, 8],
[5, 9, 8, 7, 6, 0, 4, 3, 2, 1],
[6, 5, 9, 8, 7, 1, 0, 4, 3, 2],
[7, 6, 5, 9, 8, 2, 1, 0, 4, 3],
[8, 7, 6, 5, 9, 3, 2, 1, 0, 4],
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]],
"p": [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 5, 7, 6, 2, 8, 3, 0, 9, 4],
[5, 8, 0, 3, 7, 9, 6, 1, 4, 2],
[8, 9, 1, 6, 0, 4, 3, 5, 2, 7],
[9, 4, 5, 3, 1, 2, 6, 8, 7, 0],
[4, 2, 8, 6, 5, 7, 3, 9, 0, 1],
[2, 7, 9, 3, 8, 0, 6, 4, 1, 5],
[7, 0, 4, 6, 9, 1, 3, 2, 5, 8]],
"j": [0, 4, 3, 2, 1, 5, 6, 7, 8, 9],
"check": function (str) {
var c = 0;
str.replace(/\D+/g, "").split("").reverse().join("").replace(/[\d]/g, function (u, i) {
c = Verhoeff.d[c][Verhoeff.p[i % 8][parseInt(u, 10)]];
});
return c;

},
"get": function (str) {

var c = 0;
str.replace(/\D+/g, "").split("").reverse().join("").replace(/[\d]/g, function (u, i) {
c = Verhoeff.d[c][Verhoeff.p[(i + 1) % 8][parseInt(u, 10)]];
});
return Verhoeff.j[c];
}
};

String.prototype.verhoeffCheck = (function () {
var d = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 2, 3, 4, 0, 6, 7, 8, 9, 5],
[2, 3, 4, 0, 1, 7, 8, 9, 5, 6],
[3, 4, 0, 1, 2, 8, 9, 5, 6, 7],
[4, 0, 1, 2, 3, 9, 5, 6, 7, 8],
[5, 9, 8, 7, 6, 0, 4, 3, 2, 1],
[6, 5, 9, 8, 7, 1, 0, 4, 3, 2],
[7, 6, 5, 9, 8, 2, 1, 0, 4, 3],
[8, 7, 6, 5, 9, 3, 2, 1, 0, 4],
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]];
var p = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 5, 7, 6, 2, 8, 3, 0, 9, 4],
[5, 8, 0, 3, 7, 9, 6, 1, 4, 2],
[8, 9, 1, 6, 0, 4, 3, 5, 2, 7],
[9, 4, 5, 3, 1, 2, 6, 8, 7, 0],
[4, 2, 8, 6, 5, 7, 3, 9, 0, 1],
[2, 7, 9, 3, 8, 0, 6, 4, 1, 5],
[7, 0, 4, 6, 9, 1, 3, 2, 5, 8]];

return function () {
var c = 0;
this.replace(/\D+/g, "").split("").reverse().join("").replace(/[\d]/g, function (u, i) {
c = d[c][p[i % 8][parseInt(u, 10)]];
});
return (c === 0);
};
})();

if (Verhoeff['check'](uid) === 0) {
/*return true;*/
} else {
/*return false;*/
}
}
vengateshwaran 4-Jan-18 8:05am
Thank you all

## Solution 2

This may help - Stackoverflow[^]

vengateshwaran 4-Jan-18 8:05am
function checkUID(e) {
/*e.preventDefault();*/
/*console.log(uid);*/
if (uid.length != 12) {
return false;
}

var Verhoeff = {
"d": [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 2, 3, 4, 0, 6, 7, 8, 9, 5],
[2, 3, 4, 0, 1, 7, 8, 9, 5, 6],
[3, 4, 0, 1, 2, 8, 9, 5, 6, 7],
[4, 0, 1, 2, 3, 9, 5, 6, 7, 8],
[5, 9, 8, 7, 6, 0, 4, 3, 2, 1],
[6, 5, 9, 8, 7, 1, 0, 4, 3, 2],
[7, 6, 5, 9, 8, 2, 1, 0, 4, 3],
[8, 7, 6, 5, 9, 3, 2, 1, 0, 4],
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]],
"p": [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 5, 7, 6, 2, 8, 3, 0, 9, 4],
[5, 8, 0, 3, 7, 9, 6, 1, 4, 2],
[8, 9, 1, 6, 0, 4, 3, 5, 2, 7],
[9, 4, 5, 3, 1, 2, 6, 8, 7, 0],
[4, 2, 8, 6, 5, 7, 3, 9, 0, 1],
[2, 7, 9, 3, 8, 0, 6, 4, 1, 5],
[7, 0, 4, 6, 9, 1, 3, 2, 5, 8]],
"j": [0, 4, 3, 2, 1, 5, 6, 7, 8, 9],
"check": function (str) {
var c = 0;
str.replace(/\D+/g, "").split("").reverse().join("").replace(/[\d]/g, function (u, i) {
c = Verhoeff.d[c][Verhoeff.p[i % 8][parseInt(u, 10)]];
});
return c;

},
"get": function (str) {

var c = 0;
str.replace(/\D+/g, "").split("").reverse().join("").replace(/[\d]/g, function (u, i) {
c = Verhoeff.d[c][Verhoeff.p[(i + 1) % 8][parseInt(u, 10)]];
});
return Verhoeff.j[c];
}
};

String.prototype.verhoeffCheck = (function () {
var d = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 2, 3, 4, 0, 6, 7, 8, 9, 5],
[2, 3, 4, 0, 1, 7, 8, 9, 5, 6],
[3, 4, 0, 1, 2, 8, 9, 5, 6, 7],
[4, 0, 1, 2, 3, 9, 5, 6, 7, 8],
[5, 9, 8, 7, 6, 0, 4, 3, 2, 1],
[6, 5, 9, 8, 7, 1, 0, 4, 3, 2],
[7, 6, 5, 9, 8, 2, 1, 0, 4, 3],
[8, 7, 6, 5, 9, 3, 2, 1, 0, 4],
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]];
var p = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 5, 7, 6, 2, 8, 3, 0, 9, 4],
[5, 8, 0, 3, 7, 9, 6, 1, 4, 2],
[8, 9, 1, 6, 0, 4, 3, 5, 2, 7],
[9, 4, 5, 3, 1, 2, 6, 8, 7, 0],
[4, 2, 8, 6, 5, 7, 3, 9, 0, 1],
[2, 7, 9, 3, 8, 0, 6, 4, 1, 5],
[7, 0, 4, 6, 9, 1, 3, 2, 5, 8]];

return function () {
var c = 0;
this.replace(/\D+/g, "").split("").reverse().join("").replace(/[\d]/g, function (u, i) {
c = d[c][p[i % 8][parseInt(u, 10)]];
});
return (c === 0);
};
})();

if (Verhoeff['check'](uid) === 0) {
/*return true;*/
} else {
/*return false;*/
}
}
vengateshwaran 4-Jan-18 8:05am
Thank you all