How to: Validate Against a Range of Values for ASP.NET Server Controls
You can use the ASP.NETcontrol to determine whether a user's entry falls within a specific range of values—for example, between two numbers, between two dates, or between alphabetic characters. You set the upper and lower bounds of the range as properties of a RangeValidator control. You must also specify the data type of the values that the control will validate. If the user's entry cannot be converted to the specified data type—for example, it cannot be converted to a date—the validation fails.
To validate against a range of values
Add a RangeValidator control to the page and set the following properties:
The ID of the control for which the user must provide a value.
Properties that specify the text and location of the error or errors that will appear if the user skips the control. For details, see.
Set the low and high values of the range using theand properties.
Set theproperty to specify the data type of the range settings. Use the enumeration, which enables you to specify the following types:
If the user leaves a control blank, the control passes the range validation. To force the user to enter a value, add acontrol as well. For details, see .
Add a test in your ASP.NET Web page code to check for validity. For details, see.