Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Valid email address?

Posted on 2012-03-29
3
Medium Priority
?
421 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 1500 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 1500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

618 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