要求密码的正则表达式,需要一个数字或一个非字母数字字符
发布时间:2020-12-14 06:24:45 所属栏目:百科 来源:网络整理
导读:我正在寻找一个相当具体的正则表达式,我几乎拥有它但不完全. 我想要一个需要至少5个字符的正则表达式,其中至少有一个字符是数字值或非字母数字字符. 这是我到目前为止: ^(?=.*[d]|[!@#$%^*()_-+=[{]};:|./])(?=.*[a-z]).{5,20}$ 所以问题是“或”部分
我正在寻找一个相当具体的正则表达式,我几乎拥有它但不完全.
我想要一个需要至少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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |