January 2, 2015 by Nitesh

Validate Email Using Regex in C#

Friends,

In this small post, I will show you how we can validate a string as proper email or not using Regex class in C#. Below is the code –

    public bool ValidateEmail(string emailAddress)
    {
        string regexPattern = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$";
        Match matches=Regex.Match(emailAddress,regexPattern);
        return matches.Success;
    }

The above function takes a string parameter and returns if the string is a valid email address or not.

Hope this post helps you. Keep learning and sharing. Cheers.

#.Net#C##Winforms

Support us!

If you like this site please help and make click on any of these buttons!

Powered by WordPress Popup