How to: Add and Configure a RangeValidator Control 

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

NoteNote

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.

    NoteNote

    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.

    NoteNote

    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

Tasks

How to: Add and Configure a CompareValidator Control
How to: Add and Configure a CustomValidator Control
How to: Add and Configure a RegularExpressionValidator Control
How to: Add and Configure a RequiredFieldValidator Control
How to: Add and Configure a ValidationSummary Control

Concepts

Introduction to the Validation Controls