简体   繁体   English

如何在正则表达式中启用向密码验证添加特殊字符

[英]How to enable adding special character to the password validation in regular expression

I am using this regular expression to validate password entry but this is not accepting any special character我正在使用这个正则表达式来验证密码输入,但这不接受任何特殊字符

/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$/

with this explanation:有了这个解释:

/^
  (?=.*\d)          // should contain at least one digit
  (?=.*[a-z])       // should contain at least one lower case
  (?=.*[A-Z])       // should contain at least one upper case
  [a-zA-Z0-9]{8,}   // should contain at least 8 from the mentioned characters
$/

How can I add the following to the expression as well?如何将以下内容也添加到表达式中?

/[!@#$%\^&*(){}[\]<>?/|\-]/

如果要确保有特殊字符,只需添加另一个正向前瞻组,然后将特殊字符添加到匹配组中:

/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%\^&*(){}[\]<>?/|\-])[0-9a-zA-Z!@#$%\^&*(){}[\]<>?/|\-]{8,}$/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM