Programming

Email Validation using Regular Expression in C#

Namespace

using System.Text.RegularExpressions;

 

private void btnEmailValidate_Click(object sender, EventArgs e)
{
    Regex regex = new Regex(@"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
    bool isEmailValid = regex.IsMatch(txtEmail.Text.Trim());
    if (!isEmailValid)
    {
        MessageBox.Show("Email Is Not In Correct Format"); // For Showing Message
    }
}

 

 

 

Also Read  CRUD operations in ASP.Net Web Forms using C#

About the author

Avtar

I am a blogger and I always believes in sharing a knowledge and happiness because happiness is the last journey of life.

Leave a Comment

Share
Tweet
Pin
+1
Share
0 Shares