How to check the validation of edittext for pan card like \"ABCDE1234F\". I am confused how to check the the validation for this. Please help me guys. I will appreciate any kind
Regular Exp of PANCARD- '/[A-Z]{5}\d{4}[A-Z]{1}/i';
use the following if you use angular js
$scope.panCardRegex = '/[A-Z]{5}\d{4}[A-Z]{1}/i';
HTML
<input type="text" ng-model="abc" ng-pattern="panCardRegex" />
Validating proper format should be done by this regex:
/^[A-Z]{3}[ABCFGHLJPT][A-Z][0-9]{4}[A-Z]$/
The difference from other answers is that this one takes into account that fourth letter can only take certain values. The whole regex can easily be changed to be case insensitive.
On the other hand this check is too generic and a proper validation formula for the last check letter would be much better than only checking which position has a digit or letter. Alas this formula seems not to be public.
For more information visit this repository https://github.com/riyastir/PAN-Validator
const validateAlpha = (val) => {
return val.match(/^[A-Za-z]+$/) ? true : false;
};
const validateNum = (val) => {
return val.match(/^\d+$/) ? true : false;
};
const pantype = (val) => {
switch (val) {
case "A":
type = "Association of persons (AOP)";
code = "A";
break;
case "B":
type = "Body of individuals (BOI)";
code = "B";
break;
case "C":
type = "Company";
code = "C";
break;
case "F":
type = "Firm";
code = "F";
break;
case "G":
type = "Government";
code = "G";
break;
case "H":
type = "HUF [Hindu joint family|Hindu undivided family]";
code = "H";
break;
case "L":
type = "Local authority";
code = "L";
break;
case "J":
type = "";
code = "J";
break;
case "P":
type = "Personal";
code = "P";
break;
case "T":
type = "Trust (AOP)";
code = "T";
break;
default:
type = null;
code = null;
return [type, code, false];
}
return [type, code, true];
};
const pan = (panNumber) => {
const firstSet = panNumber.substring(0, 3);
const valFirst = validateAlpha(firstSet);
if (valFirst == true) {
const secondSet = panNumber.substring(3, 4);
const valSecond = pantype(secondSet);
if (valSecond[2] == true) {
const thirdSet = panNumber.substring(5, 9);
const valThird = validateNum(thirdSet);
if (valThird == true) {
const fourthSet = panNumber.substring(9, 10);
const valFourth = validateAlpha(fourthSet);
if (valFourth == true) {
return [valSecond[0], valSecond[1], true];
} else {
return [null, null, false];
}
} else {
return [null, null, false];
}
} else {
return [null, null, false];
}
} else {
return [null, null, false];
}
};
console.log(pan("ABCPA1234D"));