正则表达式在 IE 中失败,但在 Chrome 和 Firefox 中有效?

2024-01-01

我有以下 ASP.NET 标记:

<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"   
ValidationGroup="passwordValidation"></asp:TextBox>

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic"
ControlToValidate="txtPassword" Text="Required" ValidationGroup="passwordValidation" />

<asp:RegularExpressionValidator runat="server" ControlToValidate="txtPassword"  
Text="Passwords should contain a minimum of 7 characters with at least one numeric 
character." ValidationExpression="^(?=.*\d{1})(?=.*[a-zA-Z]{2}).{7,}$"  
ValidationGroup="passwordValidation" Display="Dynamic"></asp:RegularExpressionValidator>

如果我输入像 test1234 这样的密码,它会在 chrome 和 firefox 中传递,但在 Internet Explorer 中会显示我的密码应包含至少 7 个字符且至少有一个数字字符的消息


你可能被臭名昭著的东西咬了IE 正则表达式先行错误 http://blog.stevenlevithan.com/archives/regex-lookahead-bug。您应该能够通过像其他条件一样进行长度检查并将其放在第一位来解决这个问题。

^(?=.{7,}$)(?=.*\d)(?=.*[a-zA-Z]{2}).*

但我想我看到了另一个问题。(?=.*[a-zA-Z]{2})匹配两个连续的信件;这真的是你的意图吗?如果你想要求至少两个字母,但不一定是连续的,你应该使用(?=.*[a-zA-Z].*[a-zA-Z]).

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

正则表达式在 IE 中失败,但在 Chrome 和 Firefox 中有效? 的相关文章

随机推荐