在web上可以用正则表达式来判断输入的email格式是否正确,但是如果直接用到win form这个正则表达式就不怎么起作用了。
比如 小玲 [[email protected]]台北 winform就认为是正确的格式,而web则提示是错误的。web表达式:\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*请问大家是如何解决这个问题的?
比如 小玲 [[email protected]]台北 winform就认为是正确的格式,而web则提示是错误的。web表达式:\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*请问大家是如何解决这个问题的?
public static bool IsEmail(string str)
{
if(str.Length<=0) return false;
return Regex.IsMatch(str, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
}
{
return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
}
应该是一样的啊,你的Winform和WebForm是同一台机器吗?
{
if(str.Length<=0) return false;
return Regex.IsMatch(str, @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
}