java判断字符必须包含大写字母、小写字母、数字、特殊符号且10位及以上
原文链接:https://www.cnblogs.com/yangchengdebokeyuan/p/15406523.html
package com.test.tokenserver.util;
public class test {
// public static final String PW_PATTERN = "^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)[a-zA-Z0-9\\W]{10,}$";
public static void main(String[] args) {
System.out.println(checkPswd(null));
System.out.println(checkPswd(""));
System.out.println(checkPswd("123456789987"));
System.out.println(checkPswd("asdfghjklb"));
System.out.println(checkPswd("ASDFGHJKLB"));
System.out.println(checkPswd("<>?:;'/.,;;,,,...@#$^^%^&*("));
System.out.println(checkPswd("AaaaaBbbbb"));
System.out.println(checkPswd("111111Aaaa"));
System.out.println(checkPswd("11111.Aaa"));
System.out.println(checkPswd("11111.Aaaa"));
}
/***
*
* @author Y.C
* @date 2021-10-14 13:33:28
* java判断字符是否包含大写字母、小写字母、数字、特殊符号
* (不是字母,数字,下划线,汉字的字符)的10位及以上
*
*/
public static final String PW_PATTERN = "^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)[a-zA-Z0-9\\W]{10,}$";
public static final boolean checkPswd(String pswd){
boolean falg = false;
try {
if (null==pswd&&pswd.isEmpty()&&pswd.length()>9){
return falg;
}
//不全是特殊符号 不全是数字 不全是字母 不全是大写 不全是小写
if (pswd.matches(PW_PATTERN)){
falg = true;
}
} catch (Exception e) {
falg = false;
}
return falg;
}
}