There are six validation controls included with ASP.NET as well as a summary control. Data validation with the ASP.NET validation controls is always processed on the Web server and can also optionally be processed on the user's computer.
by Shannon Horn
Aug 7, 2003
Page 5 of 8
You can compare the value entered into a control against a regular expression if you use the ASP.NET RegularExpressionValidator control. A regular expression is a series of characters that define a format expression that you can apply to a value. An overview of regular expressions is beyond the scope of this article. However, you can read about the fundamentals of regular expressions in "Getting Started with Regular Expressions" in the May/June 2003 issue of CoDe Magazine. You can also find a detailed discussion of regular expressions in the Visual Studio .NET Help file as well as in the MSDN library.
In this HTML snippet, the value entered into a textbox control is compared to a regular expression that was created to validate an e-mail address format.
ErrorMessage="E-mail address is not formatted
In the snippet above, I've linked the RegularExpressionValidator control to the txtEmailTextBox control using the ControlToValidate attribute. By now, the only attribute that isn't immediately obvious to you is the ValidationExpression attribute.
The ValidationExpression attribute defines the regular expression used to compare the value in the control to. You can see the results of the RegularExpressionValidtator control in Figure 5.