日期:2014-05-17  浏览次数:20487 次

asp的正则表达式出错?!求教!
bool IsValidEmail(string strIn) // 验证邮箱
  { 
  // Return true if strIn is in valid e-mail format. 
  return Regex.IsMatch(strIn, @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* ");
  } 

.......

  if (!IsValidEmail(TextBox_email.Text))
  {
  Response.Write("<script language=javascript>alert('请输入正确的邮箱地址!');</script>");
  return;
  }

但是,我输进去的邮箱是对的也报错! 为什么?!

------解决方案--------------------
return Regex.IsMatch(strIn, @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");

你正则表达式最后面多了个空格
------解决方案--------------------
return Regex.IsMatch(strIn, @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* ");
红色部分多了一个空格,删除,改为
return Regex.IsMatch(strIn, @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
------解决方案--------------------

修改下
return Regex.IsMatch(strIn, @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
------解决方案--------------------
C# code
\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*