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: (2938)
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:


System Message:
  • Your C# script has been sent. Please allow 48 hours for processing.


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 ]