Pan Number Format validation in Android Or Java
For PAN No. format validation in Java we need to write this simple code in Java class.
Hope this class will help you a lot.
1. First create a class called PanValidator.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class PanValidator {
public boolean isValidPan(String pan) {
Pattern mPattern = Pattern.compile("[A-Z]{5}[0-9]{4}[A-Z]{1}");
Matcher mMatcher = mPattern.matcher(pan);
return mMatcher.matches();
}
}
2. Call is call from Activity or fragment in android :
boolean isValidPanNo= new PanValidator().isValidPan(String strYourPanNo);
if( isValidPanNo)
{
// write your logic
}else{
// write your logic
}
3. Call this class from java class::
Class A{
public static void main(String args[])
{
PanValidator pv=new PanValidator();
System.out.println(pv.isValidPan("ABCDE45678E")); // valid format
System.out.println(pv.isValidPan("ABCDE4567WE")); // invalid format
}
}
Output ::
true
false
Comments
Post a Comment