/***  简单的email检查  ***/  
String.prototype.isEmail  =  function()  {  
 var  strr;  
   var  mail  =  this;  
 var  re  =  /(\w+@\w+\.\w+)(\.{0,1}\w*)(\.{0,1}\w*)/i;  
 re.exec(mail);  
 if(RegExp.$3!=  "  "  &&  RegExp.$3!=  ".  "  &&  RegExp.$2!=  ".  ")  
       strr  =  RegExp.$1+RegExp.$2+RegExp.$3;  
 else  
  if(RegExp.$2!=  "  "  &&  RegExp.$2!=  ".  ")  
           strr  =  RegExp.$1+RegExp.$2;  
  else  
        strr  =  RegExp.$1;  
 return  (strr==mail);  
}

解决方案 »

  1.   

    ereg("^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+",$email)
      

  2.   

    正如楼主所说,这些检查都是格式上的,还不够精确!真实的email地址是:当你用他发信而不被退回
      

  3.   

    完全不够精确
    [email protected]可检测的出
    [email protected]
    [email protected]
    [email protected]
      

  4.   

    http://expert.csdn.net/Expert/topic/2225/2225769.xml?temp=.448559
      

  5.   

    no
    要检查邮件地址是否正确根本就不是用正则表达式,而是使用DNS SMTP
      

  6.   

    格式的正确性--正则表达式--客户端
    地址地有效性--SMTP--服务器端
      

  7.   

    SMTP命令集
    cshuSMTP协议原始命令码和工作原理 1.SMTP是工作在两种情况下:一是电子邮件从客户机传输到服务器;二是从某一个服务器传输到另一个服务器. 
    2.SMTP是个请求/响应协议,命令和响应都是基于ASCII文本,并以CR和LF符结束。响应包括一个表示返回状态的三位数字代码. 
    3.SMTP在TCP协议25号端口监听连接请求 
    4.连接和发送过程: a.建立TCP连接 
    b.客户端发送HELO命令以标识发件人自己的身份,然后客户端发送MAIL命令 
    服务器端正希望以OK作为响应,表明准备接收 
    c.客户端发送RCPT命令,以标识该电子邮件的计划接收人,可以有多个RCPT行 
    服务器端则表示是否愿意为收件人接受邮件 
    d.协商结束,发送邮件,用命令DATA发送 
    e. 以.表示结束输入内容一起发送出去 
    f.结束此次发送,用QUIT命令退出。 5.另外两个命令: 
    VRFY---用于验证给定的用户邮箱是否存在,以及接收关于该用户的详细信息。 
    EXPN---用于扩充邮件列表。 6.邮件路由过程: 
    SMTP服务器基于‘域名服务DNS中计划收件人的域名来路由电子邮件。SMTP服务器基于DNS中的MX记录来路由电子邮件,MX记录注册了域名和相关的SMTP中继主机,属于该域的电子邮件都应向该主机发送。 若SMTP服务器mail.abc.com收到一封信要发到[email protected]: a.Sendmail请求DNS给出主机sh.abc.com的CNAME记录,如有,假若CNAME到shmail.abc.com,则再次请求shmail.abc.com的CNAME记录,直到没有为止. 
    b.假定被CNAME到shmail.abc.com,然后sendmail请求@abc.com域的DNS给出shmail.abc.com的MX记录, 
    shmail MX 5 shmail.abc.com 
    10 shmail2.abc.com 
    c. Sendmail最后请求DNS给出shmail.abc.com的A记录,即IP地址,若返回值为1.2.3.4 
    d. Sendmail与1.2.3.4连接,传送这封给[email protected]的信到1.2.3.4这台服务器的SMTP后台程序 7.SMTP基本命令集: 命令 描述 
    ------------------------------ 
    HELO 向服务器标识用户身份 
    发送者能欺骗,说谎,但一般情况下服务器都能检测到。 MAIL 初始化邮件传输 
    mail from: 
    RCPT 标识单个的邮件接收人;常在MAIL命令后面 
    可有多个rcpt to: 
    DATA 在单个或多个RCPT命令后,表示所有的邮件接收人已标识,并初始化数据传输,以.结束。 
    VRFY 用于验证指定的用户/邮箱是否存在;由于安全方面的原因,服务器常禁止此命令 
    EXPN 验证给定的邮箱列表是否存在,扩充邮箱列表,也常被禁用 
    HELP 查询服务器支持什么命令 
    NOOP 无操作,服务器应响应OK 
    QUIT 结束会话 
    RSET 重置会话,当前传输被取消 
    -------------------------------- 8. MAIL FROM命令中指定的地址是称作 envelope from地址,不需要和发送者自己的地址是一致的。 
    RCPT TO 与之等同,指明的接收者地址称为envelope to地址,而与实际的to:行是什么无关。 
    9.为什么没有RCPT CC和RCPT BCC:? 
    所有的接收者协商都通过RCPT TO命令来实现,如果是BCC,则协商发送后在对方接收时被删掉信封接收者 
    10.邮件被分为信封部分,信头部分和信体部分 
    envelope from, envelope to 与message from:, message to:完全不相干。 
    evnelope是由服务器主机间SMTP后台提供的,而message from/to是由用户提供的。有无冒号也是区别。 11. 怎样由信封部分检查是否一封信是否是伪造的? 
    a. received行的关联性。 
    现在的SMTP邮件传输系统,在信封部分除了两端的内部主机处理的之个,考虑两个公司防火墙之间 的部分,若两台防火墙机器分别为A和B,但接收者检查信封received:行时发现经过了C.则是伪造的。 
    b. received:行中的主机和IP地址对是否对应如: 
    Receibed: from galangal.org (turmeric.com [104.128.23.115] by mail .bieberdorf.edu.... 
    c. 被人手动添加在最后面的received行: 
    Received: from galangal.org ([104.128.23.115]) by mail .bieberdorf.edu (8.8.5) 
    Received: from lemongrass.org by galangal.org (8.7.3) 
    Received: from graprao.com by lemongrass.org (8.6.4)
      

  8.   

    精确检查Email地址的CLASS:================================================================================
    <?
    /*
    * email_validation.php
    *
    * @(#) $Header: /cvsroot/PHPlibrary/email_validation.php,v 1.4 1999/11/02 06:19:35 mlemos Exp $
    *
    */class email_validation_class
    {
    //var $email_regular_expression="^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}$";
    var $timeout=0;
    var $localhost="";
    var $localuser=""; Function GetLine($connection)
    {
    for($line="";;)
    {
    if(feof($connection))
    return(0);
    $line.=fgets($connection,100);
    $length=strlen($line);
    if($length>=2 && substr($line,$length-2,2)=="\r\n")
    return(substr($line,0,$length-2));
    }
    } Function PutLine($connection,$line)
    {
    return(fputs($connection,"$line\r\n"));
    } Function ValidateEmailAddress($email)
    {
    //return(eregi($this->email_regular_expression,$email)!=0);
    return(eregi("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}$",$email)!=0);
    } Function ValidateEmailHost($email,$hosts=0)
    {
    if(!$this->ValidateEmailAddress($email))
    return(0);
    $user=strtok($email,"@");
    $domain=strtok("");
    if(GetMXRR($domain,&$hosts,&$weights))
    {
    $mxhosts=array();
    for($host=0;$host<count($hosts);$host++)
    $mxhosts[$weights[$host]]=$hosts[$host];
    KSort($mxhosts);
    for(Reset($mxhosts),$host=0;$host<count($mxhosts);Next($mxhosts),$host++)
    $hosts[$host]=$mxhosts[Key($mxhosts)];
    }
    else
    {
    $hosts=array();
    if(strcmp(@gethostbyname($domain),$domain)!=0)
    $hosts[]=$domain;
    }
    return(count($hosts)!=0);
    } Function VerifyResultLines($connection,$code)
    {
    while(($line=$this->GetLine($connection)))
    {
    if(!strcmp(strtok($line," "),$code))
    return(1);
    if(strcmp(strtok($line,"-"),$code))
    return(0);
    }
    return(-1);
    } Function ValidateEmailBox($email)
    {
    if(!$this->ValidateEmailHost($email,&$hosts))
    return(0);
    if(!strcmp($localhost=$this->localhost,"") && !strcmp($localhost=getenv("SERVER_NAME"),"") && !strcmp($localhost=getenv("HOST"),""))
    $localhost="localhost";
    if(!strcmp($localuser=$this->localuser,"") && !strcmp($localuser=getenv("USERNAME"),"") && !strcmp($localuser=getenv("USER"),""))
    $localuser="root";
    for($host=0;$host<count($hosts);$host++)
    {
    if(($connection=($this->timeout ? fsockopen($hosts[$host],25,&$errno,&$error,$this->timeout) : fsockopen($hosts[$host],25))))
    {
    if($this->VerifyResultLines($connection,"220")>0 && $this->PutLine($connection,"HELO $localhost") && $this->VerifyResultLines($connection,"250")>0 && $this->PutLine($connection,"MAIL FROM: <$localuser@$localhost>") && $this->VerifyResultLines($connection,"250")>0 && $this->PutLine($connection,"RCPT TO: <$email>") && ($result=$this->VerifyResultLines($connection,"250"))>=0)
    {
    fclose($connection);
    return($result);
    }
    fclose($connection);
    }
    }
    return(-1);
    }
    };?>
    =============================================================================
      

  9.   

    应用范例:
    =============================================================================
    echo "<center><br>检查电子邮件地址的正确性:<br>";$newmail = "[email protected]";require("email_validation.php3");$validator=new email_validation_class;
    $validator->timeout=10;if(IsSet($newemail) && strcmp($newemail,""))
    {
    if(($result=$validator->ValidateEmailBox($newemail))<0)
    {
    echo "不能确定您的信箱是否正确. 您的信箱离这里太远了吧?<br>";
    return;
    }
    else

    if(!$result)

    echo "您输入的信箱地址是不正确的! :)<br>";
    return;
    }
    else 
    echo "邮箱合法!<br>";
    }
    }=============================================================================