• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

validate email address

Hey guys , i need to validate a email address in c# code.

i can use rex expression but i am using refference, please help?
0
JCWEBHOST
Asked:
JCWEBHOST
2 Solutions
 
Pratima PharandeCommented:
public static bool isEmail(string inputEmail)
{
   inputEmail  = NulltoString(inputEmail);
   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})(\]?)$";
   Regex re = new Regex(strRegex);
   if (re.IsMatch(inputEmail))
    return (true);
   else
    return (false);
}
0
 
Pratima PharandeCommented:
   public bool TestEmailRegex(string emailAddress)

            {


                  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 isStrictMatch = reStrict.IsMatch(emailAddress);

                        return isStrictMatch;

 

            }
0
 
JCWEBHOSTAuthor Commented:
where do i find this class?


Regex re = new Regex(strRegex);
0
 
jkofteCommented:
System.Text.RegularExpressions
0
 
kovilpattiBaluCommented:
check this too..

NameSpace: System.Text.RegularExpressions

      public bool chkEmail(string inEmail)
        {
            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})(\]?)$";
            Regex re = new Regex(strRegex);
            if (re.IsMatch(inEmail))
                return (true);
            else
                return (false);
        }

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now