The RegularExpressionValidator control checks that the entry matches a pattern defined by a regular expression. This type of validation enables you to check for predictable sequences of characters, such as those in e-mail addresses, telephone numbers, postal codes, and so on.
A RegularExpressionValidator works in conjunction with another control, for example a TextBox control. Add the control you want to validate to your page before you add the RegularExpressionValidator so that you can easily associate the RegularExpressionValidator with it.
To add a RegularExpressionValidator control to a page
Drag the RegularExpressionValidator control from the Toolbox task pane to your page.
Select the RegularExpressionValidator in Design view, right-click it, and click Properties on the shortcut menu.
In the Tag Properties task pane, select the control you want to validate with the RegularExpressionValidator in the ControlToValidate property dropdown.
Set the ValidationExpression property to the regular expression that the text in the control must match to be valid.
When you select the ValidationExpression property in the Tag Properties task pane, you can click the elipsis button to open the Regular Expression Editor dialog box. In this dialog box, you can choose from several predefined regular expressions, for example, Internet URL or Internet email address. You can also write your own regular expression. For more information, see Regular Expression Syntax in the MSDN library.
If you are going to use a ValidationSummary control to consolidate validation error messages, set the ValidationGroup property to the name of the group of validation controls. This can be any string, as long as all the controls in the group have the same value.
For a full description of all RegularExpressionValidator control properties, see RegularExpressionValidator Members in the MSDN library.
For more information about using validation controls to validate user input, see the topics available at How-to Topics — Validation Controls in the MSDN library.