Using the ASP.NET RangeValidator Control
The RangeValidator control enables you to check whether the value of a form field falls between a specified minimum and maximum value. You can use the RangeValidator with integer, string, date, double, and currency values.
There are five properties which you must set when using the RangeValidator control:
ControlToValidate - The id of the form field being validated.
Text - The error displayed when validation fails.
MinimumValue - The minimum value of the range of values.
MaximumValue - The maximum value of the range of values.
Type - The type of comparison to perform. Possible values are String, Integer, Double, Date, and Currency.
Be careful not to forget to set the Type attribute since the RangeValidator control defaults to performing string comparisons.
Checking for a Range a Values
The following page uses the RangeValidator control to check whether a valid age has been entered into a TextBox control. If someone enters an age less than 5 or greater than 100 then validation fails and the RangeValidator control displays its error message.