RangeValidator Class
Checks whether the value of an input control is within a specified range of values.
Assembly: System.Web (in System.Web.dll)
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)] [AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)] public ref class RangeValidator : public BaseCompareValidator
<asp:RangeValidator />
The RangeValidator control tests whether the value of an input control is within a specified range.
The RangeValidator control uses four key properties to perform its validation. The ControlToValidate property contains the input control to validate. The MinimumValue and MaximumValue properties specify the minimum and maximum values of the valid range.
The BaseCompareValidator::Type property is used to specify the data type of the values to compare. The values to compare are converted to this data type before the validation operation is performed.
Note: |
|---|
When the Type property is set to Date and the current calendar type is non-Gregorian, the validator performs server-side validation only. The validator client script supports only Gregorian calendars. |
The following table lists the different data types that can be compared.
Data Type | Description |
|---|---|
String | A string data type. |
Integer | A 32-bit signed integer data type. |
Double | A double-precision floating point number data type. |
Date | A date data type. |
Currency | A decimal data type that can contain currency symbols. |
Note: |
|---|
Validation succeeds if the input control is empty. Use a RequiredFieldValidator control to make the input control a mandatory field. |
Note: |
|---|
The RangeValidator control throws an exception if the value specified by the MaximumValue or MinimumValue property cannot be converted to the specified BaseCompareValidator::Type. |
Note: |
|---|
When you use the RangeValidator control inside an UpdatePanel control, make sure that the validator control and the control it is associated with are in the same panel. For more information about using the UpdatePanel control for partial-page updates, see Partial-Page Rendering Overview. |
For additional information on validation controls, see BaseValidator.
Accessibility
The markup rendered by default for this control might not conform to accessibility standards such as the Web Content Accessibility Guidelines 1.0 (WCAG) priority 1 guidelines. For details about accessibility support for this control, see ASP.NET Controls and Accessibility.
The following example demonstrates how to create a RangeValidator control on the Web page to determine whether the value entered into an input control is within the comparison range.
Security Note: |
|---|
This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview. |
- AspNetHostingPermission
for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission
for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note:
Security Note: