Home > php教程 > php手册 > php验证用户输入的邮箱有效性和正确性

php验证用户输入的邮箱有效性和正确性

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:33:53
Original
1614 people have browsed it

  function validate_email($email){

  $exp="^[a-z'0-9]+([._-][a-z'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";

  if(eregi($exp,$email)){ //先用正则表达式验证email格式的有效性

  if(checkdnsrr(array_pop(explode("@",$email)),"MX")){//再用checkdnsrr验证email的域名部分的有效性

  return true;

  }else{

  return false;

  }

  }else{

  return false;

  }

  }

  注意:checkdnsrr函数在win主机上是无效的!下面是国外某程序员提出的一种解决办法,另外写了个函数代替checkdnsrr函数:

  function myCheckDNSRR($hostName, $recType=''){

  if(!emptyempty($hostName)){

  if( $recType=='' ) $recType="MX";

  exec("nslookup -type=$recType $hostName", $result);

  foreach($result as $line){

  if(eregi("^$hostName",$line)){

  return true;

  }

  }

  return false;

  }

  return false;

  }

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template