Solved

Valid email address?

Posted on 2012-03-29
3
367 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When installing SharePoint 2010 RTM I came across a strange error, I was getting timeouts during the installation. I searched the web and found the best solution to be found here (http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010genera…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

17 Experts available now in Live!

Get 1:1 Help Now