C# 常用格式判断

 1         /// <summary>
 2         /// Verifies that a string is in valid e-mail format
 3         /// </summary>
 4         /// <param name="email">Email to verify</param>
 5         /// <returns>true if the string is a valid e-mail address and false if it's not</returns>
 6         public static bool IsValidEmail(string email)
 7         {
 8             if (String.IsNullOrEmpty(email))
 9                 return false;
10 
11             email = email.Trim();
12             var result = Regex.IsMatch(email, "^(?:[\\w\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\`\\{\\|\\}\\~]+\\.)*[\\w\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\`\\{\\|\\}\\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\\-](?!\\.)){0,61}[a-zA-Z0-9]?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\\[(?:(?:[01]?\\d{1,2}|2[0-4]\\d|25[0-5])\\.){3}(?:[01]?\\d{1,2}|2[0-4]\\d|25[0-5])\\]))$", RegexOptions.IgnoreCase);
13             return result;
14         }
Email邮件格式

 

posted @ 2013-03-17 08:36  自然去留  阅读(202)  评论(0编辑  收藏  举报