Solved

Valid email address?

Posted on 2012-03-29
3
408 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
[X]
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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

SharePoint Designer 2010 has tools and commands to do everything that can be done with web parts in the browser, and then some – except uploading a web part straight into a page that is edited in SPD. So, can it be done? Scenario For a recent pr…
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

707 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