How to: Add and Configure a RegularExpressionValidator Control
Use the RegularExpressionValidator control to match the value in another control against a predefined pattern.
Note
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
Add a RegularExpressionValidator control to the form that contains the target control.
Set the ControlToValidate property to the ID of the control that you want to validate.
Type a regular expression into the ValidationExpression property in the Properties window.
Alternatively, click the ellipsis button () next to the ValidationExpression property to display the Regular Expression Editor dialog box, and then select a predefined regular expression.
Set the ErrorMessage property to the text to display in the RegularExpressionValidator control if the targeted control fails validation.
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 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