The RegularExpressionValidator Server Control in

The RegularExpressionValidator Server Control:

One exciting control that developers like to use is the RegularExpressionValidator control. This control offers a lot of flexibility when you apply validation rules to your Web forms. Using the RegularExpressionValidator control, you can check a user’s input based on a pattern that you define using a regular expression.

For instance, you can define that the structure of the user input must be in the form of an e-mail address or an Internet URL; if it doesn’t match this definition, the page is considered invalid.


Making sure the text-box value is an e-mail address


<asp:TextBox ID="TextBox1" Runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
  Runat="server" ControlToValidate="TextBox1"
  ErrorMessage="You must enter an email address"

Visual Studio 2005 makes it a little easier to use regular expressions by introducing the Regular Expression Editor. This editor provides a few commonly used regular expressions that you might want to apply to your RegularExpressionValidator. To get at this editor, you work with your page from Design view. Be sure to highlight the RegularExpressionValidator1 server control in this Design view to see the control’s properties. In the Property window of Visual Studio, click the button found next to the ValidationExpression property to launch the Regular Expression Editor.

Using this editor, you can find regular expressions for things like e-mail addresses, Internet URLs, zip codes, phone numbers, and social security numbers. In addition to working with the Regular Expression Editor to help you with these sometimes complicated regular expression strings, you can also find a good-sized collection of them at an Internet site called RegExLib found at

Other Related Posts:


ASP.NET Validation Server Controls

The RequiredFieldValidator Server Control in

Validating Drop-Down Lists with the RequiredFieldValidator Control

The CompareValidator Server Control in

The RangeValidator Server Control in

The RegularExpressionValidator Server Control in

The CustomValidator Server Control in

The ValidationSummary Server Control in

One thought on “The RegularExpressionValidator Server Control in

  1. Pingback: Regularexpressionvalidator email | Figifoto

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s