微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

要求密码的正则表达式,需要一个数字或一个非字母数字字符

我正在寻找一个相当具体的正则表达式,我几乎拥有它但不完全.

我想要一个需要至少5个字符的正则表达式,其中至少有一个字符是数字值或非字母数字字符.

这是我到目前为止:

^(?=.*[\d]|[!@#$%\^*()_\-+=\[{\]};:|\./])(?=.*[a-z]).{5,20}$

所以问题是“或”部分.它将允许非字母数字值,但仍需要至少一个数值.你可以看到我有或运算符“|”在我需要的数字和非字母数字之间,但这似乎不起作用.

任何建议都会很棒.

尝试:
^(?=.*(\d|\W)).{5,20}$

一个简短的解释:

^                         # match the beginning of the input
(?=                       # start positive look ahead
  .*                      #   match any character except line breaks and repeat it zero or more times
  (                       #   start capture group 1
    \d                    #     match a digit: [0-9]
    |                     #     OR
    \W                    #     match a non-word character: [^\w]
  )                       #   end capture group 1
)                         # end positive look ahead
.{5,20}                   # match any character except line breaks and repeat it between 5 and 20 times
$                        # match the end of the input

原文地址:https://www.jb51.cc/regex/356890.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐