Products
Services
Contact Us

Scripts: C# :: Form Validation :: Library Article #8

Developer's Section

Validating Email Addresses using regular expressions in C#
By: Erobo Team Member

Hire a Developer for Related Work / Installation | $55 hr
Rating:  | Rate It:   
Average Votes: (1870)
Favorites:

In this tutotial you will learn how to validate email addresses using a simple regular expression.

The function IsEmail takes as input a string and then tries to verify if this string has the correct format for an email address. To accomplish this, we create a regular expression that checks for the typical format of an email address such as username@serverprovider.com.
See below for the function definition:

 Code Snippet 1


//Include Regular Expressions at the top of your script
using System.Text.RegularExpressions;

private bool IsEmail(String strEmail)
{
  Regex objEmailPattern=
         new Regex(@"^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$");
  return objEmailPattern.IsMatch(strEmail); 
}


See other Scripts in Form Validation

Submit Your Scripts:

If you would like to have your Javascripts published in this section please fill out
the form below:
*Your Name or Username:
Home Town:
*Email:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]