Solved

Valid email address?

Posted on 2012-03-29
3
386 Views
Last Modified: 2012-06-04
How do you check to see if an email address is valid before you send an email to that address?  I want to write a program that validates emails before I send anything.
0
Comment
Question by:VBBRett
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
echefjosef earned 500 total points
ID: 37783563
Here is an MSDN example of using RegEx to validate an Email address...  This does not validate the domain is correct, just that the email if properly formed.

http://msdn.microsoft.com/en-us/library/01escwtf.aspx
0
 
LVL 2

Assisted Solution

by:echefjosef
echefjosef earned 500 total points
ID: 37783581
Just another quick note... You can also validate using System.Net.Mail if you want to avoid RegEx statements...

public bool IsValidEmail(string email)
{
  try
   {
      var  addr = new System.Net.Mail.MailAddress(email);
      // Valid address
      return true;
   }
   catch
   {
      // The address is invalid
      return false;
   }
}
0
 

Author Comment

by:VBBRett
ID: 37967383
So if I use the following code, it will tell me if the email address is valid or not?

public bool IsValidEmail(string email)
{
  try
   {
      var  addr = new System.Net.Mail.MailAddress(email);
      // Valid address
      return true;
   }
   catch
   {
      // The address is invalid
      return false;
   }
}
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Last week I faced a strange issue recently, i have deployed SharePoint 2003 servers for one project and one of the requirements was to open SharePoint site from same server. when i was trying to open site from the same server i was getting authentic…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

776 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