Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to validate email address format?

Posted on 2008-10-21
1
223 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Call Controller Action Method from ASPX 2 22
Open a link in vb.net 2 16
Adding items to a C# list incrementally 5 30
Why use this lambda? 12 36
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…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…

861 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