How to verify PAN card?

2019-06-15 18:09发布

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.

12条回答
不美不萌又怎样
2楼-- · 2019-06-15 18:21

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.

查看更多
贪生不怕死
3楼-- · 2019-06-15 18:22

Try this one

$(document).ready(function() {
  $.validator.addMethod("pan", function(value1, element1) {
    var pan_value = value1.toUpperCase();
    var reg = /^[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[pan_value[3]];

    if (this.optional(element1)) {
      return true;
    }
    if (pan_value.match(reg)) {
      return true;
    } else {
      return false;
    }

  }, "Please specify a valid PAN Number");

  $('#myform').validate({ // initialize the plugin
    rules: {
      pan: {
        required: true,
        pan: true
      }

    },
    submitHandler: function(form) {
      alert('valid form submitted');
      return false;
    }
  });

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.js"></script>


<form id="myform" action="" method="post">
  <div>
    <label>Pan Number</label>
    <div>
      <input type="text" name="pan" value="" id="input-pan" />
    </div>
  </div>
  <button type="submit">Register</button>
</form>

查看更多
够拽才男人
4楼-- · 2019-06-15 18:22

Note that none of other answers available so far doesn't verify PAN check digit.

Here is Luhn algorythm from http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers#Java:

public static boolean luhnTest(String number){
    int s1 = 0, s2 = 0;
    String reverse = new StringBuffer(number).reverse().toString();
    for(int i = 0 ;i < reverse.length();i++){
        int digit = Character.digit(reverse.charAt(i), 10);
        if(i % 2 == 0){//this is for odd digits, they are 1-indexed in the algorithm
            s1 += digit;
        }else{//add 2 * digit for 0-4, add 2 * digit - 9 for 5-9
            s2 += 2 * digit;
            if(digit >= 5){
                s2 -= 9;
            }
        }
    }
    return (s1 + s2) % 10 == 0;
}
查看更多
Fickle 薄情
5楼-- · 2019-06-15 18:25

Regular Exp of PANCARD- '/[A-Z]{5}\d{4}[A-Z]{1}/i';

use the following if you use angular js

Controller

$scope.panCardRegex = '/[A-Z]{5}\d{4}[A-Z]{1}/i';

HTML

<input type="text" ng-model="abc" ng-pattern="panCardRegex" />
查看更多
唯我独甜
6楼-- · 2019-06-15 18:28

Very simple using simple concept.

long l = System.currentTimeMillis();

String s = l + "";
String s2 = "";

System.out.println(s.length());

for (int i = s.length() - 1; i > 8; i--) {
    s2+=s.charAt(i);
} 

String pancardNo = "AVIPJ" + s2 + "K";
System.out.println(pancardNo);

Use this unique pancard no for testing purpose .

查看更多
不美不萌又怎样
7楼-- · 2019-06-15 18:30

You can use Key press Event for PAN Card Validation in C#

enter code here

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)

    {           
        int sLength = textBox1.SelectionStart;  

        switch (sLength)
        {
            case 0:

            case 1:

            case 2:

            case 3:

            case 4:

                    if (char.IsLetter(e.KeyChar) || Char.IsControl(e.KeyChar))
                    {
                        e.Handled = false;
                    }
                    else
                    {
                        e.Handled = true;
                    }
                    break;

            case 5:

            case 6:

            case 7:

            case 8:
                    if (char.IsNumber(e.KeyChar) || Char.IsControl(e.KeyChar))
                    {
                        e.Handled = false;
                    }
                    else
                    {
                        e.Handled = true;
                    }
                    break;
            case 9:
                    if (char.IsLetter(e.KeyChar) || Char.IsControl(e.KeyChar))
                    {
                        e.Handled = false;
                    }
                    else
                    {
                        if (Char.IsControl(e.KeyChar))
                        {
                            e.Handled = false;
                        }

                        else
                        {
                            e.Handled = true;
                        }
                    }
                    break;
            default:
                    if (Char.IsControl(e.KeyChar))
                    {
                        e.Handled = false;
                    }

                    else
                    {
                        e.Handled = true;
                    }
                    break;
        }
    }
查看更多
登录 后发表回答