我在网上找了个判断EMAIL的正则表达式
也不知道什么意思就直接用了,但我输入了正确的它也说不正确
有谁能解释下这个正则表达式的意思吗?public bool IsEMail(string str)
{
   Regex rx = new Regex(@"w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*");
   return rx.IsMatch(str);
}

解决方案 »

  1.   

    ...
    网上原来的不是这个样子的吧,你自己改过了是吧//暂时没有测试环境,试下吧
    public bool IsEMail(string str)
    {
       Regex rx = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*.\w+([-.]\w+)*$");
       return rx.IsMatch(str);
    }另外这个正则只是个通用规则,不一定适合你的需求,正则这东东最好按自己的需求来写,没什么通用的
      

  2.   

    Regex rx = new Regex(@"^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$");
      

  3.   


    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm5.aspx.cs" Inherits="GridviewGenColum.WebForm5" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <input id="Text1" type="text"  onblur="check(this)"/>
            
            <script type="text/javascript">
            function checkEmail(str)
            {
            var regex = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
           
            if(str.match(regex) == null)
             return false
        else
                return true;
            }
            
            function check(obj)
            {
                if(checkEmail(obj.value))
                     alert("郵箱地址正確");
                else
                    alert("請輸入正確的郵箱地址");
            }
            </script>
        
        </div>
           
        </form>
    </body>
    </html>