51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

安全密码正则

当你回首往事时,不因碌碌无为而悔恨,不为虚度年华而羞耻,那你就可以很骄傲地和自己讲,你不负此生!

今天分享一个密码的正则,密码必须包含大、小写字母、数字、特殊符号至少三种,且长度为8-20

|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 | hljs plaintext ^(?![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代码

|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | hljs javascript if (!(/^(?![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代码

|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 | hljs java String 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()); |

赞(0)
未经允许不得转载:工具盒子 » 安全密码正则