Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

A Place to share c#.Net script which are useful to developers

Moderators

C#.NET Scripts

Validating an email address using regular expressions in C#.net

Mar 16 2012 12:00AM by Kirti M.Darji   

This script demonstrates how to validate an email address using a Regular Expression in C#

use following function to validate email address

         /// <summary>
        /// Check Email is valid or not using Regular expression
        /// </summary>
        /// <param name="Email"></param>
        /// <returns></returns>
        private static bool IsValidEmail(string Email)
        {
            string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
                @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
                @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
            System.Text.RegularExpressions.Regex regx = new System.Text.RegularExpressions.Regex(strRegex);
            return regx.IsMatch(Email) ? true : false;

        }


Kirti M.Darji
10 · 16% · 5010
9
 
1
 
0
Failed
 
0
Lifesaver
 
0
Production
 
0
Unwise



Submit

3  Comments  

  • I see this all too often in email validation.

    You're not matching on (at least) + in the username.

    For instance: your.name+whateveryouwant@gmail.com & your.name+spam@gmail.com are valid email addresses that gmail (at least) will automatically map to your.name@gmail.com. You can then use this for automatic filters on the gmail side.

    commented on May 21 2012 9:50AM
    joe.brockhaus
    2852 · 0% · 3
  • What we use is:

    ^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$
    

    It covers more than 98% of the eMail addresses we get. Note that we're using word not literal alphanumeric. Also, we're checking it as case insensitive to take care of the people that don't know that all eMail addresses are currently lower case. The length restriction is because of our database. We can't handle the longer addresses.

    commented on Jul 5 2012 12:10PM
    Dave Vroman
    129 · 1% · 399
  • All that's understandable. This wasn't targeted specifically at you, but generally across the web, if an email address is being parsed for invalid characters, almost all of the time a '+' will invalidate it. I'm just suggesting that it should not be. I ran this validation against an address with one in it and it failed, and since this went out in a newsletter I wanted to point that out. :)

    commented on Jul 5 2012 12:41PM
    joe.brockhaus
    2852 · 0% · 3

Your Comment


Sign Up or Login to post a comment.

"Validating an email address using regular expressions in C#.net" rated 5 out of 5 by 9 readers
Validating an email address using regular expressions in C#.net , 5.0 out of 5 based on 9 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]