Skip to content
Advertisement

pancard structure validation in javascript and php also

i want to do pancard validation in javascript only.

Its limited to india only.

the structure of pancard in India is as follows.. for example : AAAAA9999A

  • First five characters are letters (A-Z),
  • next 4 numerics (0-9),
  • last character letter (A-Z)

Each deductee is uniquely identified by the PAN If the PAN does not follow the above structure, then the PAN will be shown invalid

The fourth character of the PAN must be one of the following, depending on the type of assessee:

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

The fifth character of the PAN is the first character in the surname of the person to whom the PAN belongs.

so i want of check first five letters are alphabetic then follow by four letter numeric and last one is alphabetic.

so i create javascript as follow.

var panVal = $('#panNumber').val);
 var regpan = /^([a-zA-Z])([0-9])([a-zA-Z])?$/;
if(regpan.test(panVal)){
   // valid pan card number
}else // invalid pan card number

but its not working for me.

help is more appreciated for me.

Thank in advance.

Advertisement

Answer

There is a logical error in your code. Try the below code:

var panVal = $('#panNumber').val();
var regpan = /^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/;

if(regpan.test(panVal)){
   // valid pan card number
} else {
   // invalid pan card number
}

You have to limit the characters for how many time they have to occur in the given string.

Explanation

  1. ([a-zA-Z]){5} -> Alphabets should be 5 in number.

  2. ([0-9]){4} -> Numbers should be 4 in number.

  3. ([a-zA-Z]){1} -> Alphabets should be 1 in number.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement