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.
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.
Set ControltoValidate, ErrorMessage and ValidationExpression property like below:
If you want to validate Internet URL then just select Internet URL option in Validationexpressions.
Select Internet URL for validate website URL.
If we select Internet URL option from expression then the property windows looks like below screen.
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.
Now, In below screen we have entered write format email and internet url then the error message automatically remove from the screen.
I hope this RegularExpression validation control example will help you…