How to: Add and Configure a RangeValidator Control 

.NET Framework 3.0

Use the RangeValidator control to check that the value of another control falls within a range that you specify.


If the user leaves the targeted control blank, the control passes the range validation. To force the user to enter a value, add a RequiredFieldValidator control as well.

To validate the value of a control against a range of values

  1. Add a RangeValidator control to the form that contains the target control.

  2. Set the control's ControlToValidate property to the ID of the control that you want to validate.

  3. Select the type of the data being validated from one of the types in the drop-down list next to the Type property.


    If the value in the targeted control is not valid according to the Type property, the validation fails.

  4. Set the low and high values of the range with the MinimumValue and MaximumValue properties, respectively.

  5. Enter text for the ErrorMessage property. The RangeValidator control displays this text when the control being validated fails the test.


    If you enter text into the Text property, the RangeValidator control displays that text when an error occurs. If the Text property is left empty, the RangeValidator control displays the string in the ErrorMessage property.

See Also

Community Additions