Is Email Address by regex - CSharp System.Text.RegularExpressions

CSharp examples for System.Text.RegularExpressions:Match Email

Description

Is Email Address by regex

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using System;/*from   ww  w.  ja v a  2 s .co m*/

public class Main{
        public static bool IsEmailAddress(string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return false;
            }
            return Regex.IsMatch(input, @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
        }
        public static bool IsNullOrEmpty(string value)
        {
            if (value == null)
            {
                return true;
            }

            return value.Trim().Length == 0;
        }
}

Related Tutorials