16

如何检查“ABCDE1234F”等泛卡的edittext的验证。我很困惑如何检查验证。请帮帮我。我将不胜感激任何帮助。

4

16 回答 16

41

您可以将正则表达式与模式匹配一​​起使用

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

你可以测试正则表达式@

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

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

更新

另一个完整的正则表达式验证 PAN 卡号第 5 个字符取决于第 4 个字符。

于 2013-07-16T18:49:14.880 回答
10

@Raghunandan 是对的。您可以使用正则表达式。如果您看到Permanent_account_number(India)的 wiki 条目,您将了解 PAN 卡号形成的含义。您可以使用该模式来检查其有效性。相关部分如下:

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.

`

希望这可以帮助。

于 2013-07-16T18:49:25.880 回答
6

这是完美的 PAN 号 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");
}

PAN 号码有以下条件

PAN(或 PAN 编号)是一个十字符长的字母数字唯一标识符。

PAN 结构如下:AAAPL1234C

前五个字符是字母(默认为大写),后跟四个数字,最后一个(第十个)字符是字母。代码的前三个字符是三个字母,形成从 AAA 到 ZZZ 的字母序列

第四个字符标识持卡人的类型。每个持有人类型由下表中的一个字母唯一定义:

  • A — 个人协会 (AOP)
  • B - 个体 (BOI)
  • C——公司
  • F - 公司
  • G——政府
  • H - HUF(印度教不可分割的家庭)
  • L - 地方当局
  • J——人工法人
  • P - 个人(所有者)
  • T——信任(AOP)
  • F – LLP(有限责任合伙)

PAN 的第五个字符是以下任一字符的第一个字符:

  • 个人的姓氏或姓氏,如果是“个人”PAN 卡,其中第四个字符是“P”或
  • 公司/HUF/公司/AOP/信托/BOI/地方当局/人工司法人员/政府的实体、信托、社团或组织的名称,其中第四个字符是“C”、“H” ”、“F”、“A”、“T”、“B”、“L”、“J”、“G”。 最后(第十个)字符是一个字母数字,用作校验和以验证
于 2019-10-14T08:32:20.740 回答
1

有关更多信息,请访问此存储库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"));

于 2020-10-22T20:36:50.110 回答
0

泛卡验证正则表达式:

/(^([a-zA-Z]{5})([0-9]{4})([a-zA-Z]{1})$)/
于 2014-03-07T06:53:47.730 回答
0

您可以在 C# 中使用按键事件进行 PAN 卡验证

enter code here

私人无效文本框1_KeyPress(对象发送者,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;
        }
    }
于 2014-07-21T05:41:37.330 回答
0

Java中的解决方案

import java.util.Scanner;
public class PanCard 
{

    public static void main(String[] args) 
    { 
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the PAN no: "); // char [] pan=sc.nextLine().toCharArray();
        String str = sc.nextLine();
        if(str.matches ("[A-Z]{5}[0-9]{4}[A-Z]{1}"))
        {
            System.out.println("Valid PAN no");
        }
        else
        {
            System.out.println("Invalid PAN no");
        }
    }
}

输出

C:\Users\Dell\Desktop\Java 程序> java PanCard

输入 PAN 号:

ASDFG7896K

有效的 PAN 号

于 2021-07-24T09:37:58.713 回答
0

您好,对于泛卡验证,您需要在项目中执行两步过程。

1.) 创建表单并获取用户泛卡号

2.) 上传用户泛卡图片

完成这两个步骤后,在后端创建一个逻辑以进行验证。为此,您可以按照以下教程进行操作:

https://www.lelocode.com/posts/pan-verification-in-laravel-using-baidu-ocr-universal-text-recognition-%28high-precision-version%29

于 2018-10-31T06:28:52.987 回答
0

请注意,到目前为止,没有其他可用答案无法验证PAN check digit

这是来自http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers#Java的 Luhn 算法:

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;
}
于 2015-09-04T08:40:22.957 回答
0

根据所得税法,PAN卡的指导方针如下:

泛卡格式:例如。ABCDE0123F

所得税 PAN 卡是根据所得税法第 139A 条发行的。PAN 结构如下: AAAPL1234C:前五 (5) 个字符是字母,后跟四 (4) 个数字,最后 (10) 个字符是字母。第四个 (4th) 字符告知持卡人。

有关 Pan 卡的更多信息:https ://en.m.wikipedia.org/wiki/Permanent_account_number

对于代码验证“[AZ]{5}[0-9]{4}[AZ]{1}”

对于 Java

public static boolean isPanCardValid(String pan_number) {

  Pattern pattern = Pattern.compile("[A-Z]{5}[0-9]{4}[A-Z]{1}");

  Matcher matcher = pattern.matcher(pan_number);
  // Check if pattern matches
  if (matcher.matches()) {
    return true;
  } else {
    return false;
  }
}

其中 isPanCardValid() 是静态方法,它接受来自 User 的字符串作为参数(String pan_number)输入,并与 PanCard Pattern 匹配并返回值为真或假。

于 2019-01-31T06:06:50.780 回答
0

验证正确的格式应该通过这个正则表达式来完成:

/^[A-Z]{3}[ABCFGHLJPT][A-Z][0-9]{4}[A-Z]$/

与其他答案的不同之处在于,这个答案考虑到第四个字母只能取某些值。整个正则表达式可以很容易地更改为不区分大小写。

另一方面,这种检查过于笼统,最后一个检查字母的正确验证公式比只检查哪个位置有数字或字母要好得多。唉,这个公式似乎不公开。

于 2017-06-29T20:38:41.960 回答
0

PANCARD-'/[AZ]{5}\d{4}[AZ]{1}/i'的正则表达式;

如果您使用 Angular js,请使用以下内容

控制器

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

HTML

<input type="text" ng-model="abc" ng-pattern="panCardRegex" />
于 2017-05-21T04:19:12.297 回答
-1

使用简单的概念非常简单。

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);

使用这个独特的 pancard no 进行测试。

于 2016-04-27T14:16:31.863 回答
-1

试试这个

$(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>

于 2018-05-16T12:20:13.227 回答
-1
^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/

试试这个,希望会奏效

于 2016-11-11T11:09:27.550 回答
-1

public static boolean isPanCardValid(String pan_number) {

  Pattern pattern = Pattern.compile("[A-Z]{5}[0-9]{4}[A-Z]{1}");

  Matcher matcher = pattern.matcher(pan_number);
  // Check if pattern matches
  if (matcher.matches()) {
    return true;
  } else {
    return false;
  }
}

于 2019-11-19T05:50:08.360 回答