Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pancard structure validation in javascript and php also

Tags:

javascript

php

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.

like image 921
satyawan Avatar asked May 16 '16 09:05

satyawan


People also ask

How can I validate my PAN card?

Step 1: Go to e-Filing portal homepage. Step 2: Click Verify Your PAN on the e-Filing homepage. Step 3: On the Verify Your PAN page, enter your PAN, Full Name, Date of Birth and Mobile Number (accessible to you) and click Continue.

What is the format of PAN number?

PAN is a ten-digit unique alphanumeric number issued by the Income Tax Department. PAN is issued in the form of a laminated plastic card (commonly known as PAN card). Out of the first five characters, the first three characters represent the alphabetic series running from AAA to ZZZ.


2 Answers

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.

like image 120
Arun Avatar answered Oct 21 '22 15:10

Arun


Try this code it also tells about card type as asked by @RJParikh

function pan(txt)
{
	txt = txt.toUpperCase();
	var regex = /[a-zA-Z]{3}[PCHFATBLJG]{1}[a-zA-Z]{1}[0-9]{4}[a-zA-Z]{1}$/;
    var pan = {C:"Company", P:"Personal", 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"};
    pan=pan[txt[3]];
	if(regex.test(txt))
	{
    if(pan!="undefined")
      alert(pan+" card detected");
    else
	  alert("Unknown card");
    }
    else
	  alert("Unknown card");
}
<input id="pan">
<button onclick="pan(document.getElementById('pan').value)">search</button>

Hope it works well... :)

like image 30
Manav Akela Avatar answered Oct 21 '22 14:10

Manav Akela