为什么我的有效密码未通过Regex验证 [英] Why are my valid passwords not passing the Regex validation
问题描述
您好!
我正在编写密码屏幕,密码安全要求长度介于8到20个字符之间,必须至少包含一个字符阿尔法角色和至少一个数字角色和至少一个[!@#$%^&*]的特殊角色。
我拼凑了这个正则表达式,它似乎在C#中工作,但是当我开始重写代码进行javascript验证时,正则表达式将我认为有效密码标记为无效。
这里是正则表达式,因为我将它分配给RegExp:
var regExPatt = new RegExp('^(?=(?:。* [a-zA-Z] ){1})(=(?:?* \d){1})(=(?:??!* [!#@@ $%^&*]){1})(* \ n)。{8,20} $');
*注意BENE:双@@符号用于将@符号输入RegExp,否则它试图处理部分字符串,如Razor变量和事情快速横向移动。
我在哪里这个正则表达式出错?我知道它相当复杂。
密码有效:freddy1234%,freddy123 $ 5,freddy12#45,freddy1 @ 345,freddy!2345
不起作用的密码:test1234%,wilma1234%
有什么想法吗?
在此先感谢,
Andrew Giles
%^&*] 。
我拼凑了这个正则表达式,它似乎在C#中工作,但当我开始重写代码进行javascript验证时,正则表达式标记了什么我认为有效密码无效。
这是正则表达式,因为我将其分配给RegExp:
var regExPatt = new RegExp('^(?=(?:。* [a-zA-Z]){1})(?=(?:。* \ d){1})(?=( ?:?!。* [!#@@
%^&*]){1})(* \s){8,20}
');
*注意BENE:双@@符号可以获得@ sy mbol进入RegExp,否则它会尝试处理像Razor变量这样的部分字符串,而且事情会快速地横向移动。
这个正则表达式哪里出错了?我知道它相当复杂。
密码有效:freddy1234%,freddy123
Hello!
I am writing a password screen, and the requirements for the password security are somewhere between 8 and 20 characters in length, must contain AT LEAST one Alpha character and AT LEAST one numeric character and AT LEAST one special character of [!@#$%^&*].
I have cobbled together this regular expression, which appeared to work in C#, but when I started rewriting the code for a javascript validation, the regular expression is flagging what I thought were valid passwords as invalid.
Here is the regular expression as I assign it to RegExp:
var regExPatt = new RegExp('^(?=(?:.*[a-zA-Z]){1})(?=(?:.*\d){1})(?=(?:.*[!@@#$%^&*]){1})(?!.*\s).{8,20}$');
*NOTE BENE: The double @@ symbol is there to get the @ symbol into the RegExp, otherwise it tries to treat partial strings like Razor variables and things go sideways fast.
Where did I go wrong with this regular expression? I know it is fairly complicated.
Passwords that work: freddy1234%, freddy123$5, freddy12#45, freddy1@345, freddy!2345
passwords that do not work: test1234%, wilma1234%
Any ideas?
Thanks in advance,
Andrew Giles
%^&*].
I have cobbled together this regular expression, which appeared to work in C#, but when I started rewriting the code for a javascript validation, the regular expression is flagging what I thought were valid passwords as invalid.
Here is the regular expression as I assign it to RegExp:
var regExPatt = new RegExp('^(?=(?:.*[a-zA-Z]){1})(?=(?:.*\d){1})(?=(?:.*[!@@#
%^&*]){1})(?!.*\s).{8,20}
');
*NOTE BENE: The double @@ symbol is there to get the @ symbol into the RegExp, otherwise it tries to treat partial strings like Razor variables and things go sideways fast.
Where did I go wrong with this regular expression? I know it is fairly complicated.
Passwords that work: freddy1234%, freddy123
这篇关于为什么我的有效密码未通过Regex验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!