1

当我设置文本框的范围时,当我删除或评论它时出现错误页面运行请查看我的代码并告诉我其中的错误。

<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>
4

1 回答 1

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>
于 2012-06-14T05:11:15.850 回答