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  7 Best Software Development Methodologies

About the author

Author

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

0 Shares
Share
+1
Tweet
Share
Pin
Stumble