asp.net.ph

Skip Navigation Links

Validating Against a Range of Values

ASP.NET Web Forms   Web Forms Server Controls   Web Forms Validation


You can check that a user’s entry falls within a specific range of values — for example, between two numbers, between two dates, or between alphabetic characters.

To validate against a range of values

  1. Add a RangeValidator control to the page and set the following properties:

Property Setting
ControlToValidate The ID of the input control that the validation control will evaluate.
Display The display behavior for the specified validation control.
ErrorMessage The error message to display in the ValidationSummary control if validation fails.
Text The error message to display in the validation control when validation fails.
  1. Set the range to test against by setting the following properties:

Property Setting
MinimumValue and MaximumValue The low and high values of the range.
Type The data type of the range settings. Types are specified using the ValidationDataType enumeration, which allows you to use the type names String, Integer, Double, Date, or Currency. The values are converted to this type before the comparison is performed.

NOTE: 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.

  1. In your Web Forms code, check for validity. For details, see Testing Validity Programmatically.

NOTE: If the user leaves a control blank, the control passes the range validation. To force the user to enter a value, add a RequiredField validation control as well. For details, see Validating Required Entries.

See Also

Types of Validation   RangeValidator Control   RangeValidator Class   Data Entry Validation ( Client-Side )



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note