System.Web.UI.WebControls.RegularExpressionValidator Class

Validates whether the value of an associated input control matches the pattern specified by a regular expression.

See Also: RegularExpressionValidator Members

Syntax

[System.Web.UI.ToolboxData("<{0}:RegularExpressionValidator runat="server" ErrorMessage="RegularExpressionValidator"></{0}:RegularExpressionValidator>")]
public class RegularExpressionValidator : BaseValidator

Remarks

The System.Web.UI.WebControls.RegularExpressionValidator control checks 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 e-mail addresses, telephone numbers, and postal codes.

Note:

Validation succeeds if the input control is empty. If a value is required for the associated input control, use a System.Web.UI.WebControls.RequiredFieldValidator control in addition to the System.Web.UI.WebControls.RegularExpressionValidator control.

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 (by setting the BaseValidator.EnableClientScript property to false).

The regular-expression validation implementation is slightly different on the client than on the server. On the client, JScript regular-expression syntax is used. On the server, System.Text.RegularExpressions.Regex syntax is used. Since JScript regular expression syntax is a subset of System.Text.RegularExpressions.Regex syntax, it is recommended that JScript regular-expression syntax be used in order to yield the same results on both the client and the server.

Note:

When you use the System.Web.UI.WebControls.RegularExpressionValidator control inside an System.Web.UI.UpdatePanel control, make sure that the validator control and the control it is associated with are in the same panel. For more information about using the System.Web.UI.UpdatePanel control for partial-page updates, see Partial-Page Rendering Overview.

For additional information about validation controls, see System.Web.UI.WebControls.BaseValidator. For more information on regular expressions, see .NET Framework Regular Expressions.

Accessibility

For information about how to configure this control so that it generates markup that conforms to accessibility standards, see Accessibility in Visual Studio 2010 and ASP.NET 4 and ASP.NET Controls and Accessibility.

Requirements

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0