How to verify PAN card?

62,003

Solution 1

You can use Regular Expression with pattern matching

String s = "ABCDE1234F"; // get your editext value here
Pattern pattern = Pattern.compile("[A-Z]{5}[0-9]{4}[A-Z]{1}");
   
Matcher matcher = pattern.matcher(s);
// Check if pattern matches 
if (matcher.matches()) {
  Log.i("Matching","Yes");
}   

// [A-Z]{5} - match five literals which can be A to Z
// [0-9]{4} - followed by 4 numbers 0 to 9
// [A-Z]{1} - followed by one literal which can A to Z

You can test regex @

http://java-regex-tester.appspot.com/

http://docs.oracle.com/javase/tutorial/essential/regex/

Update

Another anser that is complete Regular expression validating PAN card number the 5th char depends on 4th char.

Solution 2

@Raghunandan is right. You can use regex. If you see wiki entry for Permanent_account_number(India) you'll get the meaning of the PAN card number formation. You can use the pattern to check for its validity. Relevant portion is as follows:

PAN structure is as follows: AAAAA9999A: First five characters are letters, next 4 numerals, last character letter.

1) The first three letters are sequence of alphabets from AAA to zzz
2) The fourth character informs about the type of holder of the Card. Each assesse is unique:`

    C — Company
    P — Person
    H — HUF(Hindu Undivided Family)
    F — Firm
    A — Association of Persons (AOP)
    T — AOP (Trust)
    B — Body of Individuals (BOI)
    L — Local Authority
    J — Artificial Judicial Person
    G — Government


3) The fifth character of the PAN is the first character
    (a) of the surname / last name of the person, in the case of 
a "Personal" PAN card, where the fourth character is "P" or
    (b) of the name of the Entity/ Trust/ Society/ Organisation
in the case of Company/ HUF/ Firm/ AOP/ BOI/ Local Authority/ Artificial Jurdical Person/ Govt,
where the fourth character is "C","H","F","A","T","B","L","J","G".

4) The last character is a alphabetic check digit.

`

Hope this helps.

Solution 3

This is perfect PAN number RegEx: :

String panNumber = "AAAPL1234C"; // get your editext value here
Pattern pattern = Pattern.compile("[A-Z]{3}[ABCFGHLJPTF]{1}[A-Z]{1}[0-9]{4}[A-Z]{1}");

Matcher matcher = pattern.matcher(panNumber );
// Check if pattern matches 
if (matcher.matches()) {
    Log.i("Matching","Yes");
}

There are some condition for PAN number as follow :

The PAN (or PAN number) is a ten-character long alpha-numeric unique identifier.

The PAN structure is as follows: AAAPL1234C:

The first five characters are letters (in uppercase by default), followed by four numerals, and the last (tenth) character is a letter. The first three characters of the code are three letters forming a sequence of alphabets letters from AAA to ZZZ

The fourth character identifies the type of holder of the card. Each holder type is uniquely defined by a letter from the list below:

  • A — Association of persons (AOP)
  • B — Body of individuals (BOI)
  • C — Company
  • F — Firm
  • G — Government
  • H — HUF (Hindu undivided family)
  • L — Local authority
  • J — Artificial juridical person
  • P — Individual (proprietor)
  • T — Trust (AOP)
  • F – LLP (limited liability partnership)

The fifth character of the PAN is the first character of either:

  • of the surname or last name of the person, in the case of a "personal" PAN card, where the fourth character is "P" or
  • of the name of the entity, trust, society, or organisation in the case of a company/HUF/firm/AOP/trust/BOI/local authority/artificial judicial person/government, where the fourth character is "C", "H", "F", "A", "T", "B", "L", "J", "G". The last (tenth) character is an alphabetic digit used as a check-sum to verify the

Solution 4

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"));
Share:
62,003
Sunil Kumar
Author by

Sunil Kumar

My programming specialties are Java, Kotlin, Android, and Python.

Updated on September 02, 2021

Comments

  • Sunil Kumar
    Sunil Kumar over 2 years

    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 of help.

  • Shobhit Puri
    Shobhit Puri almost 11 years
    Thanks @Raghunandan and sunil. This pattern can be used for a more thorougher check on PAN card validity. Sunil, if in Raghunandan's answer, you manage to apply few other restrictions on the fourth character in his answer, you will get what you wish precisely.
  • inquisitive
    inquisitive almost 9 years
    The first three letters are AAA-ZZZ. The Fourth letter is either of "C","H","F","A","T","B","L","J","G","P" This check can also be included, but based on the fourth letter, the fifth letter is determined if the fourth letter is P, the fifth letter is the first letter of last name of surname, and the for all others it the first letter of the name. How can we make such a regex?
  • Raghunandan
    Raghunandan almost 9 years
    @Inquisitive try posting your comment as a question instead and you will get an answer
  • inquisitive
    inquisitive almost 9 years
    @Raghunandan: Have a look here stackoverflow.com/questions/30473386/…, thanks
  • Prashant G Patil
    Prashant G Patil over 8 years
    @Raghunandan: Thanks.
  • Sumit
    Sumit over 7 years
    The regex can be simplified to [A-Z]{5}[0-9]{4}[A-Z] ({1} is redundant).
  • bbonev
    bbonev almost 7 years
    Down vote because PAN number consists of letter and digits while Luhn algorithm is defined only for digits...
  • Vadzim
    Vadzim almost 7 years
    @bbonev, it appears I didn't check the question carefully after the title. This answer is about validating payment card PAN in java. Unfortunately there is no currently suitable question on SO like for javascript. Probably it would be better to create it later.
  • Rahul Bhatt
    Rahul Bhatt about 6 years
    Does anyone know what algorithm is used for the checksum (last alphabetic check digit)?
  • Rahul Bhatt
    Rahul Bhatt about 6 years
    I did a quick validation, it seems Luhn Mod N algorithm is in use.
  • codesniffer
    codesniffer about 4 years
    @Nishan Can you provide a resource or more information for the checksum validation? How is Luhn's algorithm used with the letters?
  • Rahul Bhatt
    Rahul Bhatt about 4 years
    Luhn Mod 26 considers A=1,B=2 and so on.
  • Whirl Mind
    Whirl Mind almost 2 years
    Is there an authentic govt/income tax website that gives out the PAN validation algorithm ?
  • Raghunandan
    Raghunandan almost 2 years
    @WhirlMind not that i am aware of.