RangeValidator in ASP.NET

It confirms that user input data is within a specified range of values. The input value should come between a certain minimum and maximum value otherwise it will give error.

Set the Type property according to input data while using the RangeValidator control. By default, the Type property has the value String. If you want to specify the range of date of birth, then set Type as Date. Along with ControlToValidate and ErrorMessage you have to set the following property of RangeValidator control.

Important Properties

MinimumValue: The minimum value of the validation range.

MaximumValue: The maximum value of the validation range.

Type: Possible values are String, Integer, Double, Date, and Currency.

Example

<asp:TextBox ID="txtAge"
        runat="server"
        Width="90px">
</asp:TextBox>
<asp:RangeValidator ID="RangeValidator1"
        runat="server" ForeColor="Red"
        ControlToValidate="txtAge"
        ErrorMessage="Enter age between 18 to 60"
        MaximumValue="60" MinimumValue="18"
        Type="Integer">
</asp:RangeValidator>