This documentation is archived and is not being maintained.

Introduction to the RegularExpressionValidator Control 

Use the RegularExpressionValidator control to test whether the user input in a TextBox or SelectionList control matches a regular expression. Set the RegularExpressionValidator control's ControlToValidate to the ID of the TextBox or SelectionList control to validate.

ASP.NET Regular Expression Validator

The RegularExpressionValidator control performs validation by comparing the user input to the regular expression pattern specified in its ValidationExpression property. You can write your own regular expressions or select from a list of predefined expressions. For details, see How to: Add and Configure a RegularExpressionValidator Control.

If the user input value in the targeted control does not match the regular expression in the ValidationExpression property, the RegularExpressionValidator control displays the text defined in its ErrorMessage property.

When you add a RegularExpressionValidator control to a container control or template:

  • The ErrorMessage property is set to "RegularExpressionValidator".

  • The StyleReference property is set to "error", which is the name of a predefined style in the default StyleSheet instance.

See Also