This documentation is archived and is not being maintained.

Adding and Configuring a RegularExpressionValidator Control

Use the RegularExpressionValidator control to match the value in another control with a predefined pattern.

Note   If the user leaves the targeted control blank, the control passes the validation. To force the user to enter a value, add a RequiredFieldValidator control.

To validate the entry in a control by matching a pattern

  1. Add a RegularExpressionValidator control to the form that contains the target control.
  2. Click the arrow next to the ControlToValidate property in the Properties window to select the ID of the control that you want to validate.
  3. Type a regular expression into the ValidationExpression property in the Properties window. Alternatively, click the Ellipsis button () next to the ValidationExpression property to bring up the Regular Expression Editor dialog box. You can select from a set of standard (predefined) regular expressions, or you can type an expression.
  4. Type a text string into the ErrorMessage property in the Properties window. The RegularExpressionValidator control displays this text when the control being validated fails the test.
    Note   If you enter a string into the Text property, the RegularExpressionValidator control displays that text when an error occurs. If the Text property is left empty, the RegularExpressionValidator control displays the string in the ErrorMessage property.

See Also

Introduction to the Validation Controls | Adding and Configuring a CompareValidator Control | Adding and Configuring a CustomValidator Control | Adding and Configuring a RangeValidator Control | Adding and Configuring a RequiredFieldValidator Control | Adding and Configuring a ValidationSummary Control