7.16. Adding Validators to a Control
If you look back at Figure 7.5, you'll see that we must have two input fields to set up an appointment for the user: the user's name and the date of the appointment. A phone number is optional. If submitted, however, we want to confirm whether it is a seven-digit or a ten-digit U.S. phone number. If the user does not select a time, we'll assume that the default time on display is intended. If the user does not select a trainer, we'll make that assignment ourselves.
Web Forms provides the following validation controls (an icon for each is available in the Web Forms section of the Toolbox window):
RequiredFieldValidator, which prevents an entry from being skipped. For example, we will attach this to the TextBox ...
Get C# Primer: A Practical Approach 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.