我希望你能帮忙翻译一下关于IT技术的内容。以下是需要更新的一个asp页面中,我无法让正则表达式字段验证器工作起来的问题:
这是一个简化了重要部分的asp面板:
<asp:Panel ID="pnlEmailAddressCollection" runat="server">
<div id="POMInput-wrapper">
<div class="POMInput-FieldText">
<span class="POMInput-wrapper-text">Name:</span>
<br />
<span class="POMInput-wrapper-text">Email Address:</span>
<br />
</div>
<div class="POMInput-FieldEntry">
<asp:TextBox ID="txtEmailAddress" name="emailAddress" runat="server" CssClass="textInput"></asp:TextBox>
<asp:TextBox ID="txtUserName" runat="server" name="firstName" CssClass="textInput"></asp:TextBox>
</div>
<asp:RequiredFieldValidator ID="rfvNameValidator" runat="server"
ErrorMessage="Please enter your name"
ControlToValidate="txtUserName"
Display="None" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Please enter your email address"
ControlToValidate="txtEmailAddress"
Display="None" />
<asp:RegularExpressionValidator ID="rfvEmailValidator2" runat="server"
ErrorMessage="Please enter a valid email address"
ControlToValidate="txtEmailAddress"
Display="None"
ValidationExpression="^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}$" />
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
ShowMessageBox="true"
ShowSummary="false"
EnableClientScript="true" />
</div>
</asp:Panel>
目前无论我输入哪个电子邮件地址,都无法通过验证。asp:RequiredFieldValidator按预期工作。
我在一个测试项目中测试了正则表达式,正则表达式似乎是正确的(对有效的电子邮件返回true,对无效的电子邮件返回false)。我是否错误地设置了asp:RegularExpressionValidator?