email id validation

10/10/2011 18:22

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