Export (0) Print
Expand All

RegularExpressionValidator control

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.

  1. Drag the RegularExpressionValidator control from the Toolbox panel to your page.

  2. Select the RegularExpressionValidator in Design view, right-click it, and click Properties on the shortcut menu.

  3. In the Tag Properties panel, select the control you want to validate with the RegularExpressionValidator in the ControlToValidate property dropdown.

  4. Set the ValidationExpression property to the regular expression that the text in the control must match to be valid.

    Cc295107.alert_tip(en-us,Expression.30).gifTip:

    When you select the ValidationExpression property in the Tag Properties panel, you can click the ellipsis button Cc295107.0b8d1f68-5b69-4cd1-b928-5f7bc2a6c4dc(en-us,Expression.30).gif 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.

  5. 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 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.

Community Additions

ADD
Show:
© 2014 Microsoft