JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Creating Range Validators

As discussed in the In Depth section of this chapter, range validators test if the value of a data-entry control is inside a specified range of values. You use three main properties here—the ControlToValidate property contains the data-entry control to validate, and the MinimumValue and MaximumValue properties specify the minimum and maximum values of the valid range. If you set one of the MinimumValue and MaximumValue properties, you also must set the other. Also, don't forget to set the Type property to the data type of the values to compare; the possible values are the same as for comparison validators. And, as with other validation controls, you set the ControlToValidate property to set the control whose data you want to validate, and place the error message in the ErrorMessage property.

You can see a range validator at work in the ValidationControls example on the CD-ROM and in Figure 18.6. Here, I've set the validator's MinimumValue property to 18 and its MaximumValue property to 150. The user has entered an age under 18, so the validator is displaying its error message, as shown in Figure 18.6.

Click To expand
Figure 18.6: Using a range validator.
Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor