阿超 > 安全密码正则 安全密码正则 前端 2020-08-27 安全密码正则 2020-08-27 前端 当你回首往事时,不因碌碌无为而悔恨,不为虚度年华而羞耻,那你就可以很骄傲地和自己讲,你不负此生! 今天分享一个密码的正则,密码必须包含大、小写字母、数字、特殊符号至少三种,且长度为8-20 1^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&*`~()-+=]+$)(?![0-9\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\W_!@#$%^&*`~()-+=]{8,20}$ javascript代码 123if (!(/^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&*`~()-+=]+$)(?![0-9\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\W_!@#$%^&*`~()-+=]{8,20}$/.test(value))) { return '密码必须包含大、小写字母、数字、特殊符号至少三种,且长度为8-20'; } java代码 123456String str = "";String pattern = "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\\W_!@#$%^&*`~()-+=]+$)(?![0-9\\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\\W_!@#$%^&*`~()-+=]{8,20}$";Pattern r = Pattern.compile(pattern);Matcher m = r.matcher(str);System.out.println(m.matches());