.NET Framework Bookmark and Share   
 index > Network Class Library (System.Net) > validate an email address?
 

validate an email address?

how can I validate if the email address provided by the user does exists or not before proceeding to send an email using SmtpClient in C#?


Jassim Rahma
Jassim Rahma
  • Marked As Answer byJassim Rahma Tuesday, September 08, 2009 2:06 PM
  •  
Khanna Gaurav
  • Marked As Answer byJassim Rahma Tuesday, September 08, 2009 2:06 PM
  •  
Khanna Gaurav
Code snippet if the email address is like xxx_xxxx@xx.com:

string pattern = @"[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|].[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]@[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|].[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]-[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|].[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|].com";

System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(editemail.Text.Trim(), pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase); 
 if (!match.Success) 
{
 MessageBox.Show("You must specify valid E-mail", this.vGlobalVariables.gProductVersion, MessageBoxButtons.OK, MessageBoxIcon.Warning); 
 this.editemail.Focus();}

General regex pattern related to your requirement can be found in http://www.regular-expressions.info/email.html

Cheers:)
Mark as answer if it helps to solve your query

Rohini Chavakula

You can use google to search for other answers

Custom Search

More Threads

• WAP PUSH Using GSM
• How can I encryption in 128 bit file Upload and Download from Server...?
• SFTP - Help please!
• Determining byte count for BeginReceiveFrom if CompletedSynchronously returns true
• change my PC IP
• FTP on IIS return 421 timeout to my FtpWebRequest
• send http-form with data, work on requested side
• How to list all users on a network and send a message
• Copying files over network
• HTTPwebrequest problems