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
You can use Regular Expression with pattern matching
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
You can test regex @
http://java-regex-tester.appspot.com/
http://docs.oracle.com/javase/tutorial/essential/regex/
As per Income Tax Act, the guidelines for PAN Card are as follows:
Format For Pan Card : Eg. ABCDE0123F
Income Tax PAN card is issued under Section 139A of the Income Tax Act. The PAN structure is as follows: AAAPL1234C: The five (5) first characters are letters, followed by four (4) numerals, and the last (10th) character is a letter. The fourth (4th) character informs about the holder of the card.
For more Information regarding Pan card : https://en.m.wikipedia.org/wiki/Permanent_account_number
For Code Validation : "[A-Z]{5}[0-9]{4}[A-Z]{1}"
For 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;
}
}
where isPanCardValid() is static method, which accepts string as parameter(String pan_number) input from User and matches with PanCard Pattern and returns the value as true or false.
@Raghunandan is right. You can use regex. If you see wiki entry for Permanent_account_number(India) you'll get the meaning of the PAN card number formation. You can use the pattern to check for its validity. Relevant portion is as follows:
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.
`
Hope this helps.
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;
}
}
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 .
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>