读书人

c#检察邮箱格式

发布时间: 2012-07-29 15:26:13 作者: rapoo

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

[解决办法]

C# code
/// <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;        } 

读书人网 >C#

热点推荐