How to validate e-mail and URL in ASP .NET.

The control and the RE’s

Probability the easiest to validate the user input and check if the user entered with a valid e-mail or URL address is using the RegularExpressionValidator. It is control included in ASP .NET 3.5 which you can use to prevent users from submitting the wrong type of data into a database table.

The RegularExpressionValidator enables you to compare a value against a regular expression. You can use a regular expression to represent string patterns such as email addresses, Social Security numbers, phone numbers, dates and product codes.

We have several options to represent e-mails as a regular expression. Above I show some of them:


This regular expression matches an email address that contains non-whitespace characters, followed by an @ sign, followed by non-whitespace characters, followed by a period, followed by more non-whitespace characters.


This one will accept multiple e-mails separated only by semi-colons.


This one validates 1 or more email addresses. The e-mail addresses can be delimited with either comma or semicolon. White space is allowed after delimiter, but not necessary.


Matches a valid email address including ip’s and or port number after the @. This ER matches address like this:, or user_name@

Below some samples for Regular Expression using to validate domains, URL’s and IP’s.:


This regular expression tests the validity of a domain or hostname.


This one matches any internet URLs.


And finally, this one will match simple IP addresses.