gpt4 book ai didi

android - 正则表达式验证 PAN 卡号

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:04:14 24 4
gpt4 key购买 nike

我看过this questionthis blog对于 PAN 正则表达式。 [A-Z]{5}[0-9]{4}[A-Z]{1}。但我的问题比这更广泛。

在 PAN 卡号中:

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.

我希望正则表达式以此为基础进行检查。由于我在另一个 EditText 中得到了 Name of the person 或 Organization,因此我需要进一步验证第 4 和第 5 个字母。

原来是 [A-Z]{3}[C,H,F,A,T,B,L,J,G,P]{1}**第五个字符的东西** [0-9]{4}[A-Z]{1}

我不知道该怎样写东西

以编程方式,它可以完成,someone has done it in rails但是可以通过正则表达式来完成吗?怎么办?

最佳答案

可以与 matches() 一起使用的正则表达式是根据用户的额外输入形成的,并且后视检查前面的第 4 个字符。如果第 4 个字母是 P,我们检查姓氏中的第一个字母,如果第 4 个字母不是 P,我们检查实体名称中的第一个字母:

String rx = "[A-Z]{3}([CHFATBLJGP])(?:(?<=P)" + c1 + "|(?<!P)" + c2 + ")[0-9]{4}[A-Z]";

Sample code :

String c1 = "S"; // First letter in surname coming from the EditText (with P before)
String c2 = "F"; // First letter in name coming from another EditText (not with P before)
String pan = "AWSPS1234Z"; // true
System.out.println(pan.matches("[A-Z]{3}([CHFATBLJGP])(?:(?<=P)" + c1 + "|(?<!P)" + c2 + ")[0-9]{4}[A-Z]"));
pan = "AWSCF1234Z"; // true
System.out.println(pan.matches("[A-Z]{3}([CHFATBLJGP])(?:(?<=P)" + c1 + "|(?<!P)" + c2 + ")[0-9]{4}[A-Z]"));
pan = "AWSCS1234Z"; // false
System.out.println(pan.matches("[A-Z]{3}([CHFATBLJGP])(?:(?<=P)" + c1 + "|(?<!P)" + c2 + ")[0-9]{4}[A-Z]"));

关于android - 正则表达式验证 PAN 卡号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30473386/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com