how to validate email address in c#
  • check valid email address in c# keep one textbox and button on form and insret below code.

    code for button click event.
     private void button1_Click(object sender, EventArgs e)
    {
    if (IsEmaiIdlValid(textBox1.Text))
    {
    MessageBox.Show("Valid");
    }
    else
    {
    MessageBox.Show("Not Valid");
    }

    }

    //code of method for check
            bool IsEmaiIdlValid(string Email)
    {
    try
    {
    object Address = new System.Net.Mail.MailAddress(Email);
    return true;
    }
    catch
    {
    return false;
    }
    }
  • 1 Comment sorted by
  • good code but its also working well just try this one

    using System.Text.RegularExpressions;

     

      private void EmailIdtextBox_Leave(object sender, EventArgs e)

            {

                System.Text.RegularExpressions.Regex _email = 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 (EmailIdtextBox.Text.Length > 0)

                {

                    if (!_email.IsMatch(EmailIdtextBox.Text))

                    {

                        MessageBox.Show("Enter a valid Email-Address!""Project Shedule - Employee",MessageBoxButtons.OK, MessageBoxIcon.Error);

                        EmailIdtextBox.Text = "";

                        EmailIdtextBox.Focus();

                    }

                }

            }


Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Tagged

Popular Posts of the Week

Top Posters Weekly

Optimum Creative