EditText密码强度最强:必须含有大小写字母和数字,长度为8;
public static boolean isLetterDigit(String str) {
boolean isDigit = false;//是否包含数字
boolean isUpper = false;//是否包含大写字母
boolean isLower = false;//是否包含小写字母
boolean isLength = false;//是否长度为8
if (str.length() == 8) {
isLength = true;
}
if (isLength) {
for (int i = 0; i < str.length(); i++) {
if (Character.isDigit(str.charAt(i))) {
//包含数字
isDigit = true;
}
if (Character.isUpperCase(str.charAt(i))) {
//包含大写
isUpper = true;
}
if (Character.isLowerCase(str.charAt(i))) {
//包含小写
isLower = true;
}
}
}
String regex = "^[a-zA-Z0-9]+$";
boolean isRight = isDigit && isUpper && isLength && isLower && str.matches(regex);
return isRight;
}
OK~