Sunday, February 5, 2012

How to validate the Password Field to be alphaNumeric in android?

You just need to pass the password string in following method.........


public boolean containAlphanumeric(final String str) {
byte counter = 0;
boolean checkdigit = false, checkchar = false;
for (int i = 0; i < str.length() && counter < 2; i++) {
   // If we find a non-digit character we return false.
   if (!checkdigit && Character.isDigit(str.charAt(i))) {
checkdigit = true;
counter++;
   }
   String a = String.valueOf(str.charAt(i));
   if (!checkchar && a.matches("[a-zA-Z]*")) {
checkchar = true;
counter++;
   }
}
if (checkdigit && checkchar) {
   return true;
}
return false;
    }

1 comment: