Click here to Skip to main content
15,896,269 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
Posted
Updated 12-Dec-13 20:40pm
v2

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...
 }
 else 
 {
 // alert for wrong email id syntax
 }


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


You can get expression that suits your requirements with the below link

http://regexlib.com/Search.aspx?k=email[^]
 
Share this answer
 
For all valid format of email validation

XML
<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>
 
Share this answer
 
HI Try this code,


C#
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\-]+\" +
                 @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
           Regex regularExpression = new Regex(pattern);
           return regularExpression.IsMatch(emailID);

       }
 
Share this answer
 

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