ASP.NET Syntax ASP.NET Syntax for Validation Controls
Evaluates the value of an input control to determine whether it is between a specified upper and lower boundary.
<asp:RangeValidator id="accessID"
ControlToValidate = "ID of input control to validate"
MinimumValue = "lower bound value"
MaximumValue = "upper bound value"
Type = "datatype to convert to before comparing"
ErrorMessage = "message to display in ValidationSummary control"
Text = "message to display in control"
ForeColor = "color value"
BackColor = "color value"
runat="server" />
For information on the individual members of this class, see RangeValidator in the class library.
The RangeValidator control allows you to check whether a user’s entry is between specified lower and upper boundaries. You can check ranges within pairs of numbers, alphabetic characters, and dates. Boundaries are expressed as constants.
Use the ControlToValidate property to specify the input control to validate. The MinimumValue and MaximumValue properties specify the minimum and maximum values of the valid range, respectively.
The 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 any comparison is performed.
NOTE: If the value of the control to validate is empty, no validation functions are called and validation succeeds. To prevent the user from skipping an input control, use a RequiredFieldValidator.
Similarly, if the value of the control to validate cannot be converted to the data type specified by the Type property, validation also succeeds. It is strongly recommended that an additional CompareValidator control, with its Operator property set to DataTypeCheck, be used to verify the data type of the input value.
NOTE: The RangeValidator control throws an exception if the value specified by the MaximumValue or MinimumValue property cannot be converted to the data type specified by the Type property.
The following example demonstrates how to use the RangeValidator control to check whether the value entered in a text box is within a given minimum and maximum value.
Show me
RangeValidator Class Validating Against a Range of Values Data Entry Validation ( Client-Side )