ASP.NET RangeValidator Control

This validator evaluates the value of an input control to check that the value lies between specified ranges.

It allows us to check whether the user input is between a specified upper and lower boundary. This range can be numbers, alphabetic characters and dates.

Note: if the input control is empty, no validation will be performed.

The ControlToValidateproperty is used to specify the control to validate. The MinimumValue and MaximumValue properties are used to set minimum and maximum boundaries for the control.

RangeValidator Properties

PropertyDescription
AccessKeyIt is used to set keyboard shortcut for the control.
TabIndexThe tab order of the control.
BackColorIt is used to set background color of the control.
BorderColorIt is used to set border color of the control.
BorderWidthIt is used to set width of border of the control.
FontIt is used to set font for the control text.
ForeColorIt is used to set color of the control text.
TextIt is used to set text to be shown for the control.
ToolTipIt displays the text when mouse is over the control.
VisibleTo set visibility of control on the form.
HeightIt is used to set height of the control.
WidthIt is used to set width of the control.
ControlToValidateIt takes ID of control to validate.
ErrorMessageIt is used to display error message when validation failed.
TypeIt is used to set datatype of the control value.
MaximumValueIt is used to set upper boundary of the range.
MinimumValueIt is used to set lower boundary of the range.

Example

In the following example, we are using RangeValidator to validate user input in specified range.

// RangeValidator.aspx

Output:

ASP Range 1

It throws an error message when the input is not in range.

ASP Range 2