PHP regular expression verification Email method, PHP verification Email method _ PHP Tutorial

Source: Internet
Author: User
Tags php regular expression in domain
PHP regular expression verification Email method, PHP verification Email method. PHP regex verification Email method. PHP verification Email method this article describes the PHP regex verification Email method. Share it with you for your reference. The details are as follows: phpfunctionvalidateEmail PHP regular expression verification Email method, PHP verification Email method

This article describes the PHP regular expression verification Email method. Share it with you for your reference. The details are as follows:

<?phpfunction validateEmail($email){  $isValid = true;  $atIndex = strrpos($email, "@");  if (is_bool($atIndex) && !$atIndex)  {   $isValid = false;  }  else  {   $domain = substr($email, $atIndex+1);   $local = substr($email, 0, $atIndex);   $localLen = strlen($local);   $domainLen = strlen($domain);   if ($localLen < 1 || $localLen > 64)   {     // local part length exceeded     $isValid = false;   }   else if ($domainLen < 1 || $domainLen > 255)   {     // domain part length exceeded     $isValid = false;   }   else if ($local[0] == '.' || $local[$localLen-1] == '.')   {     // local part starts or ends with '.'     $isValid = false;   }   else if (preg_match('/\\.\\./', $local))   {     // local part has two consecutive dots     $isValid = false;   }   else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))   {     // character not valid in domain part     $isValid = false;   }   else if (preg_match('/\\.\\./', $domain))   {     // domain part has two consecutive dots     $isValid = false;   }   else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local)))   {     // character not valid in local part unless      // local part is quoted     if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local)))     {      $isValid = false;     }   }   if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))   {     // domain not found in DNS     $isValid = false;   }  }  return $isValid;}?>

I hope this article will help you with php programming.

The example in this article describes the PHP regex verification Email method. Share it with you for your reference. Details: phpfunction validateEmail...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.