Home > Regex > Regex Validator for Email

Regex Validator for Email

Original article here:
http://www.cambiaresearch.com/c4/bf974b23-484b-41c3-b331-0bd8121d5177/Parsing-Email-Addresses-with-Regular-Expressions.aspx

public bool TestEmailRegex(string emailAddress)
{
//                string patternLenient = @"w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*";
//                Regex reLenient = new Regex(patternLenient);
    string patternStrict = @"^(([^<>()[]\.,;:s@""]+"
                        + @"(.[^<>()[]\.,;:s@""]+)*)|("".+""))@"
                        + @"(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}"
                        + @".[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+"
                        + @"[a-zA-Z]{2,}))$";

    Regex reStrict = new Regex(patternStrict);
//                      bool isLenientMatch = reLenient.IsMatch(emailAddress);
//                      return isLenientMatch;
    bool isStrictMatch = reStrict.IsMatch(emailAddress);
    return isStrictMatch;
}

Advertisements
Categories: Regex
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: