如何检查pancard的edittext验证,如“ABCDE1234F”。我很困惑如何检查这个验证。请帮帮我们。我会感激任何帮助。
答案 0 :(得分:30)
您可以使用带有模式匹配的正则表达式
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
您可以测试正则表达式@
答案 1 :(得分:9)
@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.
`
希望这会有所帮助。
答案 2 :(得分:2)
这是完美的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的字母序列。
第四个字符标识卡的持有人类型。每种持有人类型均由以下列表中的字母唯一定义:
PAN的第五个字符是其中一个的第一个字符
答案 3 :(得分:0)
pan card validation
正则表达式:/(^([a-zA-Z] {5})([0-9] {4})([a-zA-Z] {1})$)/
答案 4 :(得分:0)
您可以在C#
中使用按键事件进行PAN卡验证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;
}
}
答案 5 :(得分:0)
^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/
试试这个,希望能起作用
答案 6 :(得分:0)
PANCARD的常规演样 - '/ [A-Z] {5} \ d {4} [A-Z] {1} / i';
如果使用角度js
,请使用以下内容$scope.panCardRegex = '/[A-Z]{5}\d{4}[A-Z]{1}/i';
HTML
<input type="text" ng-model="abc" ng-pattern="panCardRegex" />
答案 7 :(得分:0)
应该通过此正则表达式验证正确的格式:
/^[A-Z]{3}[ABCFGHLJPT][A-Z][0-9]{4}[A-Z]$/
与其他答案的区别在于,这一点考虑到第四个字母只能取某些值。可以很容易地将整个正则表达式更改为不区分大小写。
另一方面,这种检查过于通用,最后一个检查字母的正确验证公式比仅检查哪个位置有数字或字母要好得多。唉,这个公式似乎不公开。
答案 8 :(得分:0)
试试这个
$(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>
答案 9 :(得分:0)
您好,对于Pan Card验证,您需要在项目中执行两步过程。
1。)创建一个表格并获取用户的pan卡号
2。)上载用户全景图
完成这两个步骤后,请在后端进行逻辑验证。为此,您可以按照以下教程进行操作:
答案 10 :(得分:0)
根据《所得税法》,PAN卡的准则如下:
Pan Card格式:例如 ABCDE0123F
Income Tax PAN卡是根据《所得税法》第139A条发行的。 PAN结构如下:AAAPL1234C:前五(5)个字符是字母,后跟四(4)个数字,而最后(第10)个字符是字母。第四(第四)字符告知卡的持有人。
有关泛卡的更多信息:https://en.m.wikipedia.org/wiki/Permanent_account_number
用于代码验证:“ [A-Z] {5} [0-9] {4} [A-Z] {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()是静态方法,该方法接受从用户输入的字符串作为参数(字符串pan_number),并与PanCard模式匹配,并返回值为true或false。
答案 11 :(得分:0)
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;
}
}
答案 12 :(得分:0)
有关更多信息,请访问此存储库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"));
答案 13 :(得分:0)
Java 中的解决方案
ABCD-EF12-3456-7890
输出
<块引用>C:\Users\Dell\Desktop\Java 程序> java PanCard
输入 PAN 号:
ASDFG7896K
有效的 PAN 号
答案 14 :(得分:-1)
请注意,到目前为止,没有其他答案可以验证PAN check digit。
这是来自http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers#Java的Luhn algorythm:
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;
}
答案 15 :(得分:-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进行测试。