C# 防止范围验证程序在asp.net中使用正则表达式验证程序显示错误消息
我有一个id为C# 防止范围验证程序在asp.net中使用正则表达式验证程序显示错误消息,c#,asp.net,.net,validation,C#,Asp.net,.net,Validation,我有一个id为txtNumOfBooks的文本框,我正在根据以下3个验证器进行验证: <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtNumOfBooks" Display="Dynamic" ErrorMessage="Please enter the number of books" SetFocusOnError="True" CssClass=
txtNumOfBooks
的文本框,我正在根据以下3个验证器进行验证:
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtNumOfBooks" Display="Dynamic" ErrorMessage="Please enter the number of books" SetFocusOnError="True" CssClass="style4" ValidationGroup="CreateVac">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="txtNumOfBooks" Display="Dynamic" ErrorMessage="Please enter the valid number" ValidationExpression="[0-9]\d*[0-9]" CssClass="style4" ValidationGroup="CreateVac">
</asp:RegularExpressionValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtNumOfBooks"
Display="Dynamic" ErrorMessage="Number of books in a book shelf should be in range 1-100"
MaximumValue="100" MinimumValue="1" Type="Integer" CssClass="style4" ValidationGroup="CreateVac">
</asp:RangeValidator>
如何避免范围验证器使用正则表达式验证器消息显示其错误消息?最后,找到了答案。需要添加一个javascript函数来删除不必要的范围验证器消息。该函数为:
function clearRangeMessagePosition() {
if (document.getElementById('<%=RegularExpressionValidator1.ClientID %>').getAttribute('isValid') != true.toString()) {
document.getElementById('<%=RangeValidator1.ClientID %>').innerText = "";
}
else {
document.getElementById('<%=RangeValidator1.ClientID %>').innerText = "Please enter number of books in range 1-100";
}
}
函数clearRangeMessagePosition(){
if(document.getElementById(“”).getAttribute('isValid')!=true.toString(){
document.getElementById(“”).innerText=“”;
}
否则{
document.getElementById(“”).innerText=“请输入范围为1-100的图书数量”;
}
}
function clearRangeMessagePosition() {
if (document.getElementById('<%=RegularExpressionValidator1.ClientID %>').getAttribute('isValid') != true.toString()) {
document.getElementById('<%=RangeValidator1.ClientID %>').innerText = "";
}
else {
document.getElementById('<%=RangeValidator1.ClientID %>').innerText = "Please enter number of books in range 1-100";
}
}