Textbox Email Validation in Windows application using C#.net

30/08/2011 14:42

 private void txtCurrEmailID_Validating(object sender, CancelEventArgs e)
        {
            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 (txtCurrEmailID.Text.Length > 0)
            {
                if (!rEMail.IsMatch(txtCurrEmailID.Text))
                {
                    MessageBox.Show("Enter Valid Email ID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtCurrEmailID.SelectAll();
                    e.Cancel = true;
                }
            }
        }