怎么样在文本框中检查邮箱的格式用c#,请高手指教!

解决方案 »

  1.   


    /// <summary>
            /// 检测串值是否为合法的邮件地址格式
            /// </summary>
            /// <param name="strValue">要检测的String值</param>
            /// <returns>成功返回true 失败返回false</returns>
            public static bool CheckIsMailFormat(string strValue)
            {            
                return Utility.CheckIsFormat(@"^([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})(\]?)$", strValue);
            }        /// <summary>
            /// 检测串值是否为合法的邮件地址格式
            /// </summary>
            /// <param name="strValue">要检测的String值</param>
            /// <returns>成功返回true 失败返回false</returns>
            public static bool CheckIsMailFormatEx(string strValue)
            {
                return Utility.CheckIsFormat(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", strValue);
            }/// <summary>
            /// 检测串值是否为合法的格式
            /// </summary>
            /// <param name="strRegex">正则表达式</param>
            /// <param name="strValue">要检测的String值</param>
            /// <returns>成功返回true 失败返回false</returns>
    public static bool CheckIsFormat(string strRegex,string strValue)
    {
    if(strValue != null && strValue.Trim() != "")
    {
    Regex re = new Regex(strRegex);
    if (re.IsMatch(strValue))
    {
    return true;
    }
    else
    {
    return false;
    }
    }
    return false;
    }
      

  2.   

    用正则表达式 http://hi.baidu.com/bit5566/blog/item/c2557cef72609b3eadafd50f.html
      

  3.   

    正则表达式:
    /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/ 两个都可以
      

  4.   

    /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
      

  5.   

    貌似asp.net有的东西加验证控件!~~~ 直接托进来绑定就好了!~ 虽然效率不高 但是简单方便  
      

  6.   


      string email = "[email protected]";
                string pattern = @"/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/";
                if (Regex.IsMatch(email, pattern))
                {
                    Console.WriteLine("格式正确");
                }
                else
                {
                    Console.WriteLine("非法Email格式");
                }
      

  7.   

    @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
    或者
     /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/