How to use RegularExpression Validator in ASP.Net ?

In this asp.net article i will explain you how to use RegularExpression validation control in asp.net.

Here, we will understand RegularExpression validation validator control with an example.

RegularExpression calidator control mostly use for validate Internet E-mail address and Internet URL.

The Internet Email address must contain @ after some text and dot(.) before some text, then the address is right other wise the email address is invalid format.

Same way in Internet URL means internet website name or domain name must start with http://.

Now, first Design the web form with Three Texbox control, Name, Email and Website URL along with the one button control.

First, drag the RegularExpresion Validation control on webforms from toolbox.

RegularExpression Validation in asp.net

RegularExpression Validation in asp.net

In RegularExpression Validator control we must set below property :

ControlToValidate = TextBox control which will be validate.

ErrorMessage = Display the message when error occur.

Validation Expression = Select the expression for validation criteria.

Set the Validation Expression property of RegularExpression Validation control.

Select Internet e-mail address option for validate email address.

RegularExpression Validation in asp.net

RegularExpression Validation in asp.net

 

Set ControltoValidate, ErrorMessage and ValidationExpression property like below:

RegularExpression Validation in asp.net

RegularExpression Validation in asp.net

 

If you want to validate Internet URL then just select Internet URL option in Validationexpressions.

Select Internet URL for validate website URL.

RegularExpression Validation in asp.net

RegularExpression Validation in asp.net

If we select Internet URL option from expression then the property windows looks like below screen.

RegularExpression Validation in asp.net

RegularExpression Validation in asp.net

 

Now, Here is the output of RegularExpression validator control in asp.net.

In below screen we entered wrong email and website name then the regularexpression validator control shows the error message like Invalid Email and Invalid Url.

RegularExpression Validation in asp.net

RegularExpression Validation in asp.net

 

Now, In below screen we have entered write format email and internet url then the error message automatically remove from the screen.

RegularExpression Validation in asp.net

RegularExpression Validation in asp.net

I hope this RegularExpression validation control example will help you…

One Response to How to use RegularExpression Validator in ASP.Net ?

  1. harsh shah says:

    this website is very helpfull for me thank u

Leave a Reply

Your email address will not be published. Required fields are marked *

3 + 7 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">