How to validate Email Address in .net by C#.

Some time we need to validate Email address entered by client on server side before storing it to data base.For validate email address use below function. Pass email address to IsValidEmail function.

Make sure you are have used this name space using System.Text.RegularExpressions;

        /// <summary>
        /// Validate Email Address
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        private static bool IsValidEmail(string email)
        {
            var r = new Regex(@"^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$");

            return !string.IsNullOrEmpty(email) && r.IsMatch(email);
        }

Page Keyword: How to validate email address at server site by c#. Validate Email address at server, email validation, c# email validation.

Advertisements

2 thoughts on “How to validate Email Address in .net by C#.

  1. Pingback: Project First Sale

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s