Validating Input with the RegularExpressionValidator

Many forms of user input must be entered in very particular formats. For example, when asking for a user's e-mail address, the provided address must follow the following format: one to many alphanumeric characters, @, one to many alphanumeric characters, period, top-level domain name, such as com, net, org, edu, us, uk, fr, and so on.

For the ValidationControlTestBed.aspx ASP.NET Web page, the user is asked for a social security number. In the United States, every citizen is given a social security number, which contains nine digits and is typically written in the form

XXX-XX-XXXX

In order to ensure that a string input meets some specified format, we can use a RegularExpressionValidator, ...

Get SAMS Teach Yourself ASP.NET in 24 Hours 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.