public class PassWordUtil { static String regex_number = "[\\p{Digit}]+";// 數字 static String regex_lower = "[\\p{Lower}]+";// 正則表達式 密碼:小寫字母 static String regex_upper = "[\\p{Upper}]+";// 大寫字母 static String regex_char = "[\\p{Punct}]+";// 標點符號 public static boolean matchesPass(String user_password){ if(user_password==null){ return false; } if(user_password.length()<8){ return false; } if (user_password.matches(regex_number) || user_password.matches(regex_upper) || user_password.matches(regex_lower) || user_password.matches(regex_char)) { //return "注冊失敗,密碼不符合要求,大寫+小寫+數字+字符(至少包含2種)"; return false; } return true; } public static void main(String[] args) { String a="!!addd"; System.out.println(matchesPass(a)); } }