Click here to Skip to main content
14,973,838 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i check whether the email ID contains "@" or "." in a textbox for all email ID's for to send email, what is c# code for this
Updated 12-Dec-13 20:40pm

Hello ,

use Regular Expression for email id validation .

try this code

System.Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex(@"^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");

 if (rEMail.IsMatch(tb.Text))
  // other codes...
 // alert for wrong email id syntax

Try something like this..
bool isEmail = Regex.IsMatch(TextBox1.Text, @"Put your regex expression here")

You can get expression that suits your requirements with the below link[^]
For all valid format of email validation

<asp:RegularExpressionValidator ID="RevEMail" runat="server" ControlToValidate="txtEmailID" Display="Dynamic" ErrorMessage="is not valid" SetFocusOnError="true"  ValidationExpression="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)\b"></asp:RegularExpressionValidator>
HI Try this code,

public static bool CheckValidEmailAddress(string emailID)
           string pattern = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
                 @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
           Regex regularExpression = new Regex(pattern);
           return regularExpression.IsMatch(emailID);


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900