Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 验证控制范围验证程序使用_C#_Asp.net_Validation - Fatal编程技术网

C# 验证控制范围验证程序使用

C# 验证控制范围验证程序使用,c#,asp.net,validation,C#,Asp.net,Validation,我正在尝试为我的网站创建一个注册页面。这里我使用了范围验证器进行验证,这是我的代码 <tr> <td style="text-align:right" >Zipcode:</td> <td style="text-align:center" > <asp:TextBox ID="TextBox6" MaxLength="6" runat="server" Width="350px"> &l

我正在尝试为我的网站创建一个注册页面。这里我使用了范围验证器进行验证,这是我的代码

<tr>
    <td style="text-align:right" >Zipcode:</td>
    <td style="text-align:center" >
        <asp:TextBox ID="TextBox6" MaxLength="6" runat="server" Width="350px">
        </asp:TextBox>
    </td>
    <td>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ErrorMessage="please enter your area zipcode" ForeColor="Red" ControlToValidate="TextBox6">
        </asp:RequiredFieldValidator>
        <br />
        <asp:RangeValidator ID="RangeValidator1" ControlToValidate="TextBox6" MinimumValue="6" runat="server"  ForeColor="Red" ErrorMessage="zipcode should be 6 characters">
        </asp:RangeValidator>
    </td>
</tr>

Zipcode:

但是我得到了一些错误,比如

MaximumValue不能小于RangeValidator 1的MinimumValue 6


有人请帮我解决这个问题。

您需要在RangeAvailData上设置一个
MaximumValue
属性,还需要设置
Type
属性


请记住,按照您当前的设置方式,此验证器将不会确保用户输入的数字至少为6位,因为您的
MinimumValue
只有6位。您最好使用RegularExpressionValidator。

是的,我设置了maximumvalue属性这是我的代码,但我得到的错误与您在问题中发布的代码不同。如果您设置了
MaximumValue
,那么根据您发布的错误,它需要大于6。但是我希望我的zipcode正好是6个字符。如何做到这一点?有什么建议吗?正如我在回答中已经提到的,RangeValidator不会这样做。它只检查输入的值是否在这两个参数指定的范围内。您应该使用RegularExpressionValidator。