ASP.NET RangeValidator control
Definition and usage
The RangeValidator control is used to check whether the user's input value is between two values. It can compare different types of values, such as numbers, dates, and characters.
Note:If the input control is empty, the validation will not fail. Please use the RequiredFieldValidator control to make the field required.
Note:If the input value cannot be converted to the specified data type, the validation will not fail. Please use the CompareValidator control, set its Operator property to ValidationCompareOperator.DataTypeCheck, so that you can verify the data type of the input value.
Property
Property | Description |
---|---|
BackColor | Background color of the RangeValidator control |
ControlToValidate | ID of the control to be validated |
Display |
Display behavior of the validation control. Valid values include:
|
EnableClientScript | Boolean value, specifies whether to enable client-side validation. |
Enabled | Boolean value, specifies whether to enable the validation control. |
ErrorMessage |
Texto que se muestra en el control ValidationSummary cuando falla la validación. Nota: Si no se establece la propiedad Text, el texto también se mostrará en el control de validación. |
ForeColor | Color de primer plano del control. |
id | ID único del control. |
IsValid | Booleano, indica si el control de entrada asociado ha pasado la validación. |
MaximumValue | Especifica el valor máximo del control de entrada. |
MinimumValue | Especifica el valor mínimo del control de entrada. |
runat | Especifica que el control es un control de servidor. Debe establecerse en "server". |
Tipo |
Especifica el tipo de datos del valor que se debe verificar. Los tipos son:
|
Texto | Mensaje que se muestra cuando la validación falla. |
Ejemplo
- RangeValidator
- En este ejemplo, declaramos un control TextBox, un control Button y un control RangeValidator en el archivo .aspx. Si la validación falla, se mostrará el texto "¡La fecha debe estar entre 1/1/2002 y 31/5/2002!" en el control RangeValidator.
- RangeValidator 2
- En este ejemplo, declaramos un control TextBox, un control Button, un control Label y un control RangeValidator en el archivo .aspx. La función submit() puede detectar si la página es válida. Si es válida, se muestra "¡La página es válida!" en el control Label. Si no es válida, se muestra "¡La página no es válida!" en el control Label. Si la validación falla, se muestra "¡El valor debe estar entre 1 y 100!" en el control RangeValidator.