CodeCopy

September 4, 2009

Validate Email address

Filed under: c# — sterndorff @ 16:17
Tags: ,

CodeCopy:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace CodeCopy
{
    public class EmailValidator
    {
        public static bool IsValidEmail(string email)
        {
            if (string.IsNullOrEmpty(email))
                return false;

            string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
                  @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
                  @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
            Regex re = new Regex(strRegex);
            if (re.IsMatch(email.Trim()))
                return (true);
            else
                return (false);
        }
    }
}

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.