Click here to Skip to main content
16,021,125 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
only in c# code.

dont use any controls or javascript
Posted
Updated 11-Apr-12 3:35am
v2

Try this:
C#
void EmailValidation(object sender, CancelEventArgs e)
       {
           System.Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex(@"^[a-zA-Z][\w\.-]{0,68}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");
           if (txtEmail.Text.Length > 0)
           {
               if (!rEMail.IsMatch(txtEmail.Text))
               {
                   MessageBox.Show("Invalid e-mail id.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                   txtEmail.SelectAll();
                   e.Cancel = true;
               }
           }
       }
 
Share this answer
 
Comments
fjdiewornncalwe 11-Apr-12 9:36am    
Please don't do people's homework for them. There is a reason we don't do that here.

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