Home >Backend Development >PHP Tutorial >PHP verifies the validity and correctness of the email entered by the user_PHP tutorial

PHP verifies the validity and correctness of the email entered by the user_PHP tutorial

WBOY
WBOYOriginal
2016-07-22 09:03:001152browse

 function validate_email($email){

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

 if(eregi($exp,$email)){ //First use regular expression to verify the validity of the email format

 if(checkdnsrr(array_pop(explode("@",$email)),"MX")){//Use checkdnsrr to verify the validity of the domain name part of the email

 return true;

 }else{

 return false;

 }

 }else{

 return false;

 }

 }

Note: The checkdnsrr function is invalid on the win host! The following is a solution proposed by a foreign programmer. He also wrote a function to replace the checkdnsrr function:

 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;

 }

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/371826.htmlTechArticle function validate_email($email){ $exp=^[a-z'0-9]+([._-][a-z'0-9]+)*@([a-z0-9]+( [._-][a-z0-9]+))+$; if(eregi($exp,$email)){ //First use regular expression to verify the validity of the email format if(c...
Statement:
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