asp.net.ph

Skip Navigation Links

RegularExpressionValidator Control

ASP.NET Syntax   ASP.NET Syntax for Validation Controls


Evaluates the value of an input control to determine whether it matches a pattern defined by a regular expression.

Syntax

<asp:RegularExpressionValidator id="accessID"
   ControlToValidate = "ID of input control to validate"
   ValidationExpression = "the regular expression pattern to test against"
   ErrorMessage = "message to display in ValidationSummary control"
   Text = "message to display in control"
   ForeColor = "color value"
   BackColor = "color value"
   runat="server" />

For information on the individual members of this class, see RegularExpressionValidator in the class library.

Remarks

The RegularExpressionValidator control is used to determine whether the value of an input control matches a pattern defined by a regular expression. This type of validation allows you to check for predictable sequences of characters, such as those in social security numbers, e-mail addresses, telephone numbers, postal codes, and so on.

NOTE: If the value of the control to validate is empty, no validation functions are called and validation succeeds. To prevent the user from skipping an input control, use a RequiredFieldValidator.

Both server-side and client-side validation are performed unless the browser does not support client-side validation or client-side validation is explicitly disabled ( the EnableClientScript property is set to false ).

Use the ValidationExpression property to specify the regular expression used to validate input control. The regular expression validation syntax is slightly different on the client than on the server. On the client, JScript regular expression syntax is used. On the server, Regex syntax is used. Since JScript regular expression syntax is a subset of Regex syntax, it is recommended that you use JScript regular expression syntax in order to yield the same results on both the client and the server.

For additional information, see Regular Expressions.

Example

The following example demonstrates how to use the RegularExpressionValidator control to check the value entered in a text box for a specific pattern. In this example, the pattern is a zip code with five digits.

 Show me 

See Also

RegularExpressionValidator Class   Validating Against Patterns   Regular Expressions Language Elements   Data Entry Validation ( Client-Side )



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note