ASP.NET RangeValidator Control
Validation Server Controls
Definition and Usage
The RangeValidator control is used to check whether the user's input value is between two values. It can compare values of different types, such as numbers, dates, and characters.
**Note:** If the input control is empty, validation does not fail. Use the RequiredFieldValidator control to make the field required.
**Note:** If the input value cannot be converted to the specified data type, validation does not fail. Use the CompareValidator control and set its Operator property to ValidationCompareOperator.DataTypeCheck to validate the data type of the input value.
property
| property | Description |
|---|---|
| BackColor | The background color of the RangeValidator control. |
| ControlToValidate | The id of the control to be validated. |
| Display | The display behavior of the validation control. Valid values are:
|
- Currency
- Date
- Double
- Integer
- String
Example
RangeValidator
In this example, we declare a TextBox control, a Button control, and a RangeValidator control in the .aspx file. If validation fails, the text "The date must be between 1/1/2002 and 31/5/2002!" will be displayed in the RangeValidator control.
RangeValidator 2
In this example, we declare a TextBox control, a Button control, a Label control, and a RangeValidator control in the .aspx file. The submit() function checks whether the page is valid. If valid, it returns "The page is valid!" in the Label control. If invalid, it returns "The page is not valid!" in the Label control. If validation fails, "The value must be from 1 to 100!" is displayed in the RangeValidator control.
Validation Server Controls