(1)密码中连续数字超过3个;(说明:比如123,234,345)。
(2)密码不能有连续3个以上的数字或字母(说明:比如111,222,333,AAA,,bbb)。
(3)密码由6~16位数字和字母组成
这个正则搞不定,还是写代码搞吧
用代码吧,正则只能匹配指定字符,不能匹配字符之间的关联,所以第一个用正则肯定实现不了
代码实现也很简单:
private static boolean isPassword(String st) {
if (st == null) return false;
if (st.matches("^(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9]{6,16}$")) {//6-16至少有一个字母和数字
for (int i = 0; i < st.length() - 2; i++) {
char c0 = st.charAt(i);
char c1 = st.charAt(i + 1);
char c2 = st.charAt(i + 2);
if ((c0 == c1 && c0 == c2) || (c0 == c1 - 1 && c0 == c2 - 2)) {//相等或者相差1
return false;
}
}
return true;
}
return false;
}