验证范围及规则:'密码需包含数字、大小写字母、特殊字符,长度8-20,不能出现连续的相同字母或数字、不能出现顺序的字母或数字,不能使用手机号或邮箱作为密码'
@Test
public void regularValidation() {
String regex = "/^(?=.*\d)(?!.*(\d)\1{2})(?!.*(012|123|234|345|456|567|678|789|987|876|765|654|543|432|321|210))(?=.*[a-z])(?=.*[A-Z])(?=.*[^\da-zA-Z\s]).{8,20}$/";
String password = "Sc.aa1def";
if (!Pattern.compile(regex).matcher(password).matches()) {
System.err.println("弱密码");
} else {
System.err.println("强密码");
}
}