true, if is valid email address - CSharp System.Text.RegularExpressions

CSharp examples for System.Text.RegularExpressions:Match Email

Description

true, if is valid email address

Demo Code


using System.Threading;
using System.Text.RegularExpressions;
using System.Text;
using System.Security.Cryptography;
using System.Net;
using System.Linq;
using System.Globalization;
using System.Collections.Generic;
using System;/*  w w  w. j  ava 2s  .co m*/

public class Main{
        /// <summary>
        /// true, if is valid email address
        /// from http://www.davidhayden.com/blog/dave/
        /// archive/2006/11/30/ExtensionMethodsCSharp.aspx
        /// </summary>
        /// <param name="s">email address to test</param>
        /// <returns>true, if is valid email address</returns>
        public static bool IsValidEmailAddress(string s)
        {
            return new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,6}$").IsMatch(s);
        }
}

Related Tutorials