Home » Php » pancard structure validation in javascript and php also

pancard structure validation in javascript and php also

Posted by: admin July 12, 2020 Leave a comment

Questions:

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.

How to&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.

Answer:

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… 🙂

Answer:

Well, with HTML 5 you don’t have to write any javascript to add validation, at least for this PAN validation, use below input tag for this,

<input type="text" id="pan_no" name="pan_no" placeholder="PAN No." maxlength="10" pattern="[a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}" title="Please enter valid PAN number. E.g. AAAAA9999A" required/>

Enjoy!!

Answer:

Try below code.

function ValidatePAN() { 
  var Obj = document.getElementById("textPanNo");
        if (Obj.value != "") {
            ObjVal = Obj.value;
            var panPat = /^([a-zA-Z]{5})(\d{4})([a-zA-Z]{1})$/;
            if (ObjVal.search(panPat) == -1) {
                alert("Invalid Pan No");
                Obj.focus();
                return false;
            }
          else
            {
              alert("Correct Pan No");
              }
        }
  } 
<input type="text" ID="textPanNo" MaxLength="10" onblur="ValidatePAN(this);">
<input type="button" value="Check" onclick="ValidatePAN();">

Answer:

For JavaScript you can use

function validatePAN(panVal){
    var regpan = /^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/;
    if(regpan.test(panVal)){
        return true;
    } else {
        return false;
    }
}

Answer:

I have my working script here to validate Pan Number, I think it should help you.

    function validatePanNumber(panNum)
         {

           var regpan = /^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/;

           if(regpan.test(panNum) == false)
           {

              document.getElementById("status").innerHTML = "Permanent Account Number is not yet valid.";

           }
           else
            {

            document.getElementById("status").innerHTML = "You have entered a valid Permanent Account Number !";

            }
       }

Now Call this function on key event of text box

  <input type="text" name="panNum" onkeyup="validatePanNumber(this.value);"> 

Answer:

Use the following code:

function pan_validate(pan) {
  var regpan = /^([A-Z]){5}([0-9]){4}([A-Z]){1}?$/;
  if (regpan.test(pan) == false) {
    document.getElementById("status").innerHTML = "PAN Number Not Valid.";
  } else {
    document.getElementById("status").innerHTML = "";
  }
}
<input type="text" class="form-control input_capital" MaxLength="10" onkeyup="pan_validate(this.value);" placeholder="Please Enter Pan Card" name="pancard" autocomplete="off">
<b style="color:red"><span id="status"></span></b>

Answer:

As per Income Tax Act, the guidelines for PAN Card are as follows:

Format For Pan Card : Eg. ABCDE0123F

    var panVal = $('ABCDE0123F').val();

    var vali = /^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/;
if(vali.test(panVal)){

   // valid pan card number

} else {

   // invalid pan card number
}

Answer:

Use as provided:

if(!empty($_POST["panNumber"]) && $_POST["panNumber"] != "" ){

    $panNumber = $_POST["panNumber"];
    if (!preg_match('/^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/',$_POST["panNumber"])) {
        $err .= "Only 11 digit pin code are allowed which containes 5 Charactor, 4 alphabate & 1 charctor in <strong> PAN NUMBER </strong>"."<br>";
    }else{
        $panNumber = $_POST["panNumber"];
    }       
}else{
    $err .= "Please Enter your PAN CARD number"."<br>";
}