I have created a code for validating PAN card details and it's working absolutely fine in every device except ASUS device which is running on Android 5.0.2. That phone is accepting only one letter and rest 9 digits.
Here is my code in MainActivity:
private EditText txt;
txt.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
txt.removeTextChangedListener(this);
String mDetails=txt.getText().toString().toUpperCase();
txt.setText(mDetails.replaceAll("[^a-zA-Z0-9]", ""));
txt.setSelection(txt.getText().toString().length());
txt.addTextChangedListener(this);
if(s.length()==10)
{
if(!isValidPancard(s.toString()))
{
txt.setError("Invalid pan card");
}
else
Toast.makeText(MainActivity.this,"Valid",Toast.LENGTH_LONG).show();
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
Validation logic:
public static boolean isValidPancard(String pancardNo) {
String PAN_PATTERN = "[A-Z]{3}[P]{1}[A-Z]{1}[0-9]{4}[A-Z]{1}";
Pattern pattern = Pattern.compile(PAN_PATTERN);
Matcher matcher = pattern.matcher(pancardNo);
return matcher.matches();
}