Is email by regular expression : Email « Regular Expressions « C# / C Sharp






Is email by regular expression

 

//http://metalinq.codeplex.com/license
//Apache License 2.0 (Apache)


using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Text.RegularExpressions;

namespace MetaliqSilverlightSDK
{
    public class StringUtil
    {
        public static bool isEmail(string inputEmail)
        {
            bool result = false;
            try
            {
                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(inputEmail))
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
            }
            return result;
        }
    }
}

   
  








Related examples in the same category

1.Compare two DateTime values
2.Use regular expression to check email format
3.Regular expression to match an email address