Public paste
idn-php-email
By: pontus | Date: Oct 18 2018 20:10 | Format: PHP | Expires: never | Size: 1 KB | Hits: 707

  1.                 var $regex = '/^([a-zA-Z0-9&_?\/`!|#*$^%=~{}+\'-]+|"([\x00-\x0C\x0E-\x21\x23-\x5B\x5D-\x7F]|\\[\x00-\x7F])*")(\.([a-zA-Z0-9&_?\/`!|#*$^%=~{}+\'-]+|"([\x00-\x0C\x0E-\x21\x23-\x5B\x5D-\x7F]|\\[\x00-\x7F])*"))*@([a-zA-Z0-9&_?\/`!|#*$^%=~{}+\'-]+|\[([\x00-\x0C\x0E-\x5A\x5E-\x7F]|\\[\x00-\x7F])*\])(\.([a-zA-Z0-9&_?\/`!|#*$^%=~{}+\'-]+|\[([\x00-\x0C\x0E-\x5A\x5E-\x7F]|\\[\x00-\x7F])*\]))*$/';
  2.  
  3.                 function validate($email, $checkDomain = false)
  4.                 {
  5.                         if (function_exists('idn_to_ascii')) {
  6.                           if ($parts = explode('@', $email)) {
  7.                                 if (sizeof($parts) == 2) {
  8.                                   foreach ($parts as &$part) {
  9.                                         $part = idn_to_ascii($part);
  10.                                   }
  11.                                   $email = implode('@', $parts);
  12.                                 }
  13.                           }
  14.                         }
  15.  
  16.                         if (preg_match($this->regex . 'D', $email)) {
  17.                                 if ($checkDomain && function_exists('checkdnsrr')) {
  18.                                         $tokens = explode('@', $email);
  19.                                         if (checkdnsrr($tokens[1], 'MX') || checkdnsrr($tokens[1], 'A')) {
  20.                                                 return true;
  21.                                         }
  22.                                         return false;
  23.                                 }
  24.                                 return true;
  25.                         }
  26.                         return false;
  27.                 }