ASP.NET 正则表达式验证器无法在 Internet Explorer 7 上运行
我使用以下正则表达式验证器来确保输入的密码满足 1 个大写字母、1 个小写字母、1 个数字和 1 个允许的特殊字符的要求:
<asp:RegularExpressionValidator ID="rev_txtNewPassword" runat="server" Display="Dynamic"
ErrorMessage=" Password does not meet requirements" ControlToValidate="txtNewPassword" ValidationGroup="password"
ValidationExpression="^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#$%^&*]).{8,16}$"></asp:RegularExpressionValidator>
这适用于 FireFox、Chrome、Safari、Internet Explorer 8 和 9。只是在Internet Explorer 7上不起作用。无论在密码框中输入什么,它都说不符合要求。这是自定义 SharePoint 2010 Web 部件的一部分。
知道为什么表达式验证器不能仅在 IE7 上运行吗?
谢谢
I am using the following Regular Expression Validator to ensure the password enter meets the requirements of 1 upper case, 1 lower case, 1 number, and 1 allowed special character:
<asp:RegularExpressionValidator ID="rev_txtNewPassword" runat="server" Display="Dynamic"
ErrorMessage=" Password does not meet requirements" ControlToValidate="txtNewPassword" ValidationGroup="password"
ValidationExpression="^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#$%^&*]).{8,16}$"></asp:RegularExpressionValidator>
This works in FireFox, Chrome, Safari, Internet Explorer 8 and 9. It just doesn't work on Internet Explorer 7. No matter what is entered into the password box, it says it doesn't meet the requirements. This is part of a custom SharePoint 2010 web part.
Any ideas why the expression validator isn't working only on IE7?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
按照OP的要求,我把解决方案放在这里,这样每个人都可以看到这个问题已经解决。该问题是由 IE regex Lookahead bug 引起的,并提出了原始解决方案作者:艾伦·摩尔。解决方案可以在这里找到:
解决方案
As the OP requests, I put the solution here so everybody can view this question as solved. The problem is caused by the IE regex lookahead bug and the original solution is made by Alan Moore. The solution can be found here:
Solution
即使它有效,用户应该如何知道如何形成传递该表达式的有效密码?他们是否应该一直猜测直到得到答案?如果您需要如此复杂的密码,为您的用户生成它可能是礼貌的做法。即使你为用户列出了所有规则,一旦规则变得过于复杂,他们也会感到困难。
ASP.NET Membership 有一个基本的密码生成器,例如,
如果您想要更复杂的东西,您可以使用 RNGCryptoServiceProvider.GetBytes() 自行生成随机字节数组,然后将这些字节转换为字符,使用模数来限制范围。
另请注意,您可以在 中设置密码强度正则表达式会员配置:
Even if it worked, how is the user supposed to know how to form a valid password that passes that expression? Are they supposed to keep guessing until they get it? If you need such a complex password, it might be polite to generate it for your users. Even if you list all the rules for the user, they will struggle with it once it gets too complex.
ASP.NET Membership has a basic password generator, e.g.
If you want something more sophisticated, you can roll your own using RNGCryptoServiceProvider.GetBytes() to generate an array of random bytes, then convert those bytes into characters, using a modulo to restrict the range.
Note also that you can set a password strength regex in Membership configuration: