首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

c#检察邮箱格式

2012-07-29 
c#检查邮箱格式怎么样在文本框中检查邮箱的格式用c#,请高手指教![解决办法]C# code/// summary/// 检测

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;        } 

热点排行