ASP.NET RangeValidator Controls
Definition and Usage
RangeValidator control value for detecting user input is between two values. You can compare different types of values, such as numbers, dates, and characters.
Note: If theinput control is empty, validation will not fail. Please use the RequiredFieldValidator control to make the field required (mandatory).
Note: If the input value can not be converted to the specified data type, verification will not fail.Use CompareValidator control, its Operator property to ValidationCompareOperator.DataTypeCheck, so you can check the data type of the input value.
Attributes
属性 | 描述 |
---|---|
BackColor | RangeValidator 控件的背景颜色。 |
ControlToValidate | 要验证的控件的 id。 |
Display | 验证控件的显示行为。合法值有:
|
EnableClientScript | 布尔值,规定是否启用客户端验证。 |
Enabled | 布尔值,规定是否启用验证控件。 |
ErrorMessage | 当验证失败时,在 ValidationSummary 控件中显示的文本。 注释:如果未设置 Text 属性,文本也会显示在验证控件中。 |
ForeColor | 控件的前景颜色。 |
id | 控件的唯一 id。 |
IsValid | 布尔值,指示由 ControlToValidate 指定的控件是否通过验证。 |
MaximumValue | 规定输入控件的最大值。 |
MinimumValue | 规定输入控件的最小值。 |
runat | 规定该控件是一个服务器控件。必须设置为 "server"。 |
Type | 规定要检测的值的数据类型。类型有:
|
Text | 当验证失败时显示的消息。 |
Examples
RangeValidator
In this example, we declare a TextBox control in an .aspx file, a Button control, and a RangeValidator control. If the validation fails, the control will be displayed in RangeValidator text "The date must be between 1/1/2002 and 31/5/2002!".
RangeValidator 2
In this example, we declare in an .aspx file a TextBox control, a Button control, a Label control, and a RangeValidator control. submit () function detects the page is valid. If so, then in the Label control returns "The page is valid!". If not, then in the Label control returns "The page is not valid!". If the validation fails, RangeValidator control display "The value must be from 1 to 100!".
Validation Server Controls