当我设置我的文本框的范围时,当我删除或评论它时会出现错误页面运行请看我的代码并告诉我错误。
<asp:TextBox ID="TxtName" runat="server" ValidationGroup="Adduser" MaxLength="32"
Width="200px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ValidationGroup="Adduser"
ErrorMessage="Provide user name" ControlToValidate="TxtName" Display="Dynamic">*</asp:RequiredFieldValidator>
<%--<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ValidationGroup="Adduser" ControlToValidate="TxtName" ErrorMessage="User ID Must be at least 8 Alpha Numeric Characters." ValidationExpression="^[a-zA-Z0-9]{8,}$">*</asp:RegularExpressionValidator>--%>
<asp:RangeValidator ID="RangeValidator2" runat="server" ErrorMessage="The ID Must Be 8 Characters." MaximumValue="32" MinimumValue="8" ControlToValidate="TxtName" Type="String"></asp:RangeValidator>
</td>
答案 0 :(得分:1)
不应使用RangeValidator作为String类型而是使用RegularExpressionValidator
试试这个,
<asp:TextBox ID="TxtName"
runat="server"
ValidationGroup="Adduser"
MaxLength="32"
Width="200px"></asp:TextBox>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator2"
runat="server"
ValidationGroup="Adduser"
ControlToValidate="TxtName"
ErrorMessage="User ID Must be at least 8 Alpha Numeric Characters."
ValidationExpression="[a-zA-Z0-9]{8}">*</asp:RegularExpressionValidator>