public static String passwordCheck(String password) { if(password.matches("^.*[\s]+.*$") || password.matches(".*\s+$")) { return "密码不可有空格"; } if(!password.matches("^[a-zA-Z0-9\!\@\#\,\.\;\:\+\=\-\_]+$")) { return "密码必须是数字、字母、!@#,.;:+=-_符号的组合"; } if(password.length() < 8 || password.length() > 16) { return "密码长度在 8 - 16 之间"; } if(password.matches("^(?:\d+|[a-zA-Z]+|[!@#$%^&]+)$")) { return "密码强度弱,密码必须是数字、字母、!@#,.;:+=-_符号的组合"; } return null; }