Solved

How to validate email address format?

Posted on 2008-10-21
1
221 Views
Last Modified: 2013-12-17
Hi

I need to send email with a list. When I insert the email list, I need to validate the format of it in C# code.

while (!str.EndOfStream)
                {
                        string email = str.ReadLine().Split(new char[] { ' ,' });
                        //add to email program
}

How can I validate email address with proper format?

Thanks
0
Comment
Question by:techques
1 Comment
 
LVL 16

Accepted Solution

by:
Gyanendra Singh earned 50 total points
ID: 22768289
refer this code sample
public static bool isEmail(string 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);

}

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now