c#检查邮箱格式 怎么样在文本框中检查邮箱的格式用c#,请高手指教! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /// <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; } 用正则表达式 http://hi.baidu.com/bit5566/blog/item/c2557cef72609b3eadafd50f.html 正则表达式:/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/ 两个都可以 /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; 貌似asp.net有的东西加验证控件!~~~ 直接托进来绑定就好了!~ 虽然效率不高 但是简单方便 string email = "[email protected]"; string pattern = @"/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/"; if (Regex.IsMatch(email, pattern)) { Console.WriteLine("格式正确"); } else { Console.WriteLine("非法Email格式"); } @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"或者 /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/ 【200分】如何让PropertyGrid显示控件的Name属性 请教如何设置dataGridView控件某一列的数据类型格式 一道关于装箱的问题(C#) C# 自己定义控件怎么增加事件? [winforms]: 数据库插入图片 用于 Microsoft Office 系统的 Microsoft Visual Studio 工具哪里可以下载??? 想做个播放ppt得播放器 请问如何获取listview中选中的多个项目?~! C# 中无法立即完成一个非阻挡性套接字操作,急救 求微信扫码支付开发的流程或细节说明 datagridview DataGridViewColumn问题 C# 问题
/// <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;
}
/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/ 两个都可以
string email = "[email protected]";
string pattern = @"/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/";
if (Regex.IsMatch(email, pattern))
{
Console.WriteLine("格式正确");
}
else
{
Console.WriteLine("非法Email格式");
}
或者
/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/