Created
December 14, 2014 00:44
-
-
Save woodss/0aa6e0e787b76e6c6a6b to your computer and use it in GitHub Desktop.
How to validate an e-mail address in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net.Mail; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace MailChecking | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string EmailToCheck = Console.ReadLine(); | |
if (IsValidEmail(EmailToCheck)) | |
{ | |
Console.WriteLine("Yes, that was a valid e-mail address!"); | |
} | |
else | |
{ | |
Console.WriteLine("No, that was not a valid e-mail address!"); | |
} | |
Main(args); | |
} | |
private static bool IsValidEmail(string EmailToCheck) | |
{ | |
try | |
{ | |
MailAddress mail = new MailAddress(EmailToCheck); | |
return true; | |
} | |
catch (Exception e) | |
{ | |
return false; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment