2010-07-13 23 views
2

我有以下的asp.net标记:正则表达式在IE中失败,但适用于Chrome和Firefox?

<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,但我的密码应该至少包含7个字符的消息至少一个数字字符显示在Internet Explorer中

+0

我在IE8上测试了VS2010中的上述代码,并且无法重现该问题。你能提供更多细节吗? – Kelsey 2010-07-13 21:14:20

+0

...特别是,您正在测试哪个版本的IE? – 2010-07-13 21:35:02

+0

我正在使用IE 8 – Xaisoft 2010-07-13 21:36:13

回答

2

您可能被臭名昭着的IE regex lookahead bug咬了。你应该能够通过使长度检查像其他条件一样向前看,并将其放在第一位。

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

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

+0

我会给你一个镜头,让你知道。我正在阅读有关它的帖子。我是新来的正规表达式,所以先行者超过了我的头。 – Xaisoft 2010-07-13 21:36:54

+0

你可能想看看这个网站,如果你还没有:http://www.regular-expressions.info/ – 2010-07-14 02:07:52

+0

我得去测试它,它的工作。感谢您的链接。 – Xaisoft 2010-07-14 17:41:43

相关问题