Public paste
php-idn-email-validation
By: pne | Date: Oct 18 2018 20:22 | Format: PHP | Expires: never | Size: 1.35 KB | Hits: 794

  1.  
  2. // Valid
  3. $email_a = 'test@xn--38j2b6b6e.xn--q9jyb4c';
  4. $email_b = 'testä@にほんご.みんな';
  5. $email_c = 'jo@faß.de';
  6. $email_d = 'asd@√.com';
  7.  
  8. // Invalid
  9. $email_z = 'asd@Ⱥbby.com';
  10. $email_y = 'a@‡.com';
  11. $email_x = 'asd@ԛәлп.com';
  12.  
  13. ->validate($email_?,false);
  14.  
  15.  
  16.                 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])*\]))*$/';
  17.  
  18.                 function validate($email, $checkDomain = false)
  19.                 {
  20.                         if (function_exists('idn_to_ascii')) {
  21.                           if ($parts = explode('@', $email)) {
  22.                                 if (sizeof($parts) == 2) {
  23.                                   foreach ($parts as &$part) {
  24.                                         $part = idn_to_ascii($part);
  25.                                   }
  26.                                   $email = implode('@', $parts);
  27.                                 }
  28.                           }
  29.                         }
  30.  
  31.                         if (preg_match($this->regex . 'D', $email)) {
  32.                                 if ($checkDomain && function_exists('checkdnsrr')) {
  33.                                         $tokens = explode('@', $email);
  34.                                         if (checkdnsrr($tokens[1], 'MX') || checkdnsrr($tokens[1], 'A')) {
  35.                                                 return true;
  36.                                         }
  37.                                         return false;
  38.                                 }
  39.                                 return true;
  40.                         }
  41.                         return false;
  42.                 }