Creating Your Own Validation

There may be times when you can't find one of the built-in validation controls that handles your specific data. For example, which control could verify that a number the user has entered is an even number (if that was a requirement of your page)? There isn't such a control, but ASP.NET provides the CustomValidator control, which allows you to specify procedures to be run in order to validate the data in the associated input control.

For this example, your goal is to ensure that users enter either CA, NV, or AZ into the State text box on the page. You could use a DropDownList control for this, or you could use a RegularExpressionValidator control (setting the expression to be CA|NV|AZ). However, for the sake of this ...

Get ASP.NET Developer's JumpStart now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.