有人可以帮我理解为什么这个不起作用吗?
public boolean validatePassword(String pass){
final int MIN_LENGTH = 6;// Minimum length 6
// check if password is correct length and that it does not
// contain any invalid characters
if(pass.length() >= MIN_LENGTH && !pass.matches("(.*)[^.-_+!?=a-zA-Z0-9](.*)")){
// 4 rules, 3 should be fulfilled
// 1: Contain upper characters (A-Z)
// 2: Contain lower characters (a-z)
// 3: Contain numbers (0-9)
// 4: Contain following character . - _ + ! ? =
int ruleCount = 0; // counting fulfilled rules
if(pass.matches("(.*)[A-Z](.*)")) ruleCount++;
if(pass.matches("(.*)[a-z](.*)")) ruleCount++;
if(pass.matches("(.*)[0-9](.*)")) ruleCount++;
if(pass.matches("(.*)[.-_+!?=](.*)")) ruleCount++;
if(ruleCount >= 3) return true; // password verified
}
// password not verified
return false;
}
由于某些原因,该程序接受包含大小写字母的密码,并且还会验证包含数字和小写字母的密码有效性。但它只应在符合4个规则中的3个规则时才进行验证。