RegularExpressionValidator Class
Validates whether the value of an associated input control matches the pattern specified by a regular expression.
Assembly: System.Web (in System.Web.dll)
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)] [AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)] public ref class RegularExpressionValidator : public BaseValidator
<asp:RegularExpressionValidator />
The 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 RequiredFieldValidator control in addition to the 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 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 RegularExpressionValidator control inside an 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 UpdatePanel control for partial-page updates, see Partial-Page Rendering Overview. |
For additional information about validation controls, see BaseValidator. For more information on regular expressions, see .NET Framework Regular Expressions.
Accessibility
The markup rendered by default for this control might not conform to accessibility standards such as the Web Content Accessibility Guidelines 1.0 (WCAG) priority 1 guidelines. For details about accessibility support for this control, see ASP.NET Controls and Accessibility.
The following example demonstrates how to use the RegularExpressionValidator control to validate a five-digit postal code.
Security Note: |
|---|
This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview. |
- AspNetHostingPermission
for operating in a hosted environment. Demand value: LinkDemand. Permission value: Minimal.
- AspNetHostingPermission
for operating in a hosted environment. Demand value: InheritanceDemand. Permission value: Minimal.
System.Web.UI::Control
System.Web.UI.WebControls::WebControl
System.Web.UI.WebControls::Label
System.Web.UI.WebControls::BaseValidator
System.Web.UI.WebControls::RegularExpressionValidator
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note:
Security Note: