我有一个RegularExpressionValidator来验证我拥有的电子邮件输入, 如果输入与Regular-expression匹配,则它完美地工作 但是,如果我输入错误的电子邮件,它会显示错误消息,如果我在输入中修复电子邮件,它不会重新检查它,错误消息不会允许我单击Registeration按钮 - 或者更像它被点击,但是没有事件被解雇 -
编辑:添加了ASPX代码
< table width="100%">< tr><td>Username:</td>
<td>
<input runat="server" id="txtUsername" type="text" size="30" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="txtUsername" ErrorMessage="*"></asp:RequiredFieldValidator
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ErrorMessage="Username has to be atleast between 4-8 "
ValidationExpression="[A-Z]{4-8}"
ControlToValidate="txtUsername"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td> Email:</td><td>
<input runat="server" id="txtemail" type="text" size="30" /></td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtemail" ErrorMessage="*">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtemail" ErrorMessage="Format must be: abc@abc.com"
ValidationExpression="^[A-Za-z0-9._%+-]+@([A-Za-z0-9-]+\.)+([A-Za-z0-9]{2,4}|museum)$">
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
<asp:Label runat="server" ForeColor="red" ID="lblerror"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button runat="server" Text="Register"
ID="btnSubmit" Width="118px" onclick="btnSubmit_Click" />
</td>
</tr>
</table>
答案 0 :(得分:0)
您是否在btnSubmit_Click方法中检查了Page.IsValid
?
此外,username
的验证表达式看起来不正确,请在最小和最大长度之间使用逗号。
<击> ValidationExpression = “[A-Z] {4-8}”击>
ValidationExpression =“[A-Z] {4,8}”