www.pudn.com > UptoLog_SomeTestApplication.zip > ValidateEmail.cs


using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Text.RegularExpressions; 
using UptoLog.Satellite; 
using System.Diagnostics; 
 
namespace SomeWindowsApplication.Validate 
{ 
    public class ValidateEmail 
    { 
        public static bool Validate(ErrorLevel logLevel, string emailAddress) 
        { 
            Regex test = new Regex(@"^([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})(\]?)$"); 
            Match matchResult = test.Match(emailAddress); 
            if (matchResult.Success) 
            { 
                return true; 
            } 
            else 
            { 
                string report = string.Format("The e-mail address is invalid. The input value is: {0}", emailAddress); 
                string message = "Invalid e-mail address"; 
                if (logLevel == ErrorLevel.Warning) 
                { 
                    Log.LogWarning(report, message, new StackTrace(true).ToString()); 
                } 
                else 
                { 
                    Log.LogError(report, message, new StackTrace(true).ToString()); 
                } 
 
                return false; 
            } 
        } 
    } 
}