运用正则判断密码必须包含大写字母、小写字母、数字、特殊符号且10及以上
1 package com.test.tokenserver.util; 2 3 4 public class test { 5 // 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,}$"; 6 7 public static void main(String[] args) { 8 System.out.println(checkPswd(null)); 9 System.out.println(checkPswd("")); 10 System.out.println(checkPswd("123456789987")); 11 System.out.println(checkPswd("asdfghjklb")); 12 System.out.println(checkPswd("ASDFGHJKLB")); 13 System.out.println(checkPswd("<>?:;'/.,;;,,,...@#$^^%^&*(")); 14 System.out.println(checkPswd("AaaaaBbbbb")); 15 System.out.println(checkPswd("111111Aaaa")); 16 System.out.println(checkPswd("11111.Aaa")); 17 System.out.println(checkPswd("11111.Aaaa")); 18 19 } 20 21 /*** 22 * 23 * @author Y.C 24 * @date 2021-10-14 13:33:28 25 * java判断字符是否包含大写字母、小写字母、数字、特殊符号 26 * (不是字母,数字,下划线,汉字的字符)的10位及以上 27 * 28 */ 29 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,}$"; 30 public static final boolean checkPswd(String pswd){ 31 boolean falg = false; 32 try { 33 if (null==pswd&&pswd.isEmpty()&&pswd.length()>9){ 34 return falg; 35 } 36 //不全是特殊符号 不全是数字 不全是字母 不全是大写 不全是小写 37 if (pswd.matches(PW_PATTERN)){ 38 falg = true; 39 } 40 41 } catch (Exception e) { 42 falg = false; 43 } 44 return falg; 45 } 46 47 }
本文来自博客园,作者:綦霖,转载请注明原文链接:https://www.cnblogs.com/yc-weblog/p/15406523.html