sunil sunil - 22 days ago 9
Java Question

How to verify card PAN?

How to check the validation of edit text for pan card like "ABCDE1234F". I am confused how to check the the validation for this. please help me guys i appreciated

Answer

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/

Comments