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

CSharp examples for System.Text.RegularExpressions:Match Email

Description

Is Valid Email by regex

Demo Code


using System.Web;
using System.Text.RegularExpressions;
using System.IO;/* www. ja va  2 s .  co  m*/
using System.Security.Cryptography;
using System.Diagnostics;
using System.Collections.Generic;
using System;

public class Main{
        public static bool IsValidEmail(string inputEmail)
        {
            // inputEmail = NulltoString(inputEmail);
            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))
                return (true);
            else
                return (false);
        }
}

Related Tutorials