Share via


How to: Add and Configure a RegularExpressionValidator ControlĀ 

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

NoteNote

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

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. Set the ControlToValidate property to 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 (ASP.NET Mobile Designer ellipse) next to the ValidationExpression property to display the Regular Expression Editor dialog box, and then select a predefined regular expression.

  4. Set the ErrorMessage property to the text to display in the RegularExpressionValidator control if the targeted control fails validation.

    NoteNote

    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 defined in the ErrorMessage property.

See Also

Tasks

How to: Add and Configure a CompareValidator Control
How to: Add and Configure a CustomValidator Control
How to: Add and Configure a RangeValidator Control
How to: Add and Configure a RequiredFieldValidator Control
How to: Add and Configure a ValidationSummary Control

Concepts

Introduction to the Validation Controls