问题描述
我有以下的asp.net标记:
I have the following asp.net markup:
<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个字符,其中至少有一个数字字符的消息
If I type in a password like test1234, it passes in chrome and firefox, but the message that my password should contain a minimum of 7 characters with at least one numeric character is shown in internet explorer
推荐答案
您很可能得到由臭名昭著的。您应该能够通过使长度检查超前像其他条件,并把它首先要解决的。
You're probably getting bitten by the infamous IE regex lookahead bug. You should be able to work around that by making the length check a lookahead like the other conditions, and putting it first.
^(?=.{7,}$)(?=.*\d)(?=.*[a-zA-Z]{2}).*
不过,我想我看到了另一个问题。
两个连续的字母相匹配(= * [A-ZA-Z] {2}?);是真正的意图是什么?如果你想要求至少两个字母,但不一定是连续的,你应该使用(?=。* [A-ZA-Z] * [A-ZA-Z])
。
But I think I see another problem. (?=.*[a-zA-Z]{2})
matches two consecutive letters; is that really your intent? If you want to require at least two letters, but not necessarily consecutive, you should use (?=.*[a-zA-Z].*[a-zA-Z])
.
这篇关于普通防爆pression在IE中失败,但在Chrome和Firefox的作品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!