java判断密码必须包含字母,数字,特殊字符

public static void main(String[] args) {
String password = "{123456789\"sWEWEF";
//数字
String REG_NUMBER = ".*\\d+.*";
//大写字母
String REG_UPPERCASE = ".*[A-Z]+.*";
//小写字母
String REG_LOWERCASE = ".*[a-z]+.*";
//特殊字符
String REG_SYMBOL = ".*[~!@#$%^&*()_+|<>,.?/:;'\\[\\]{}\"]+.*";
System.out.println("密码长度="+password.length());
if ( password.length() <8 || password.length()>18) {
System.err.println("密码长度8-18");
}
if(!(password.matches(REG_NUMBER)&&((password.matches(REG_UPPERCASE))||(password.matches(REG_LOWERCASE)))
&&password.matches(REG_SYMBOL))){
System.err.println("密码必须包含字母,数字,特殊字符");
}else{
System.out.println("符合条件");
}
}

 

 

有补充请留言。

posted @ 2022-07-06 09:30  幽魂~~  阅读(1395)  评论(0编辑  收藏  举报