daily pastebin goal
71%
SHARE
TWEET

Untitled

a guest Mar 14th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function validEmail($email)
  2. {
  3.    $isValid = true;
  4.    $atIndex = strrpos($email, "@");
  5.    if (is_bool($atIndex) && !$atIndex)
  6.    {
  7.       $isValid = false;
  8.    }
  9.    else
  10.    {
  11.       $domain = substr($email, $atIndex+1);
  12.       $local = substr($email, 0, $atIndex);
  13.       $localLen = strlen($local);
  14.       $domainLen = strlen($domain);
  15.       if ($localLen < 1 || $localLen > 64)
  16.       {
  17.          // local part length exceeded
  18.          $isValid = false;
  19.       }
  20.       else if ($domainLen < 1 || $domainLen > 255)
  21.       {
  22.          // domain part length exceeded
  23.          $isValid = false;
  24.       }
  25.       else if ($local[0] == '.' || $local[$localLen-1] == '.')
  26.       {
  27.          // local part starts or ends with '.'
  28.          $isValid = false;
  29.       }
  30.       else if (preg_match('/\\.\\./', $local))
  31.       {
  32.          // local part has two consecutive dots
  33.          $isValid = false;
  34.       }
  35.       else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
  36.       {
  37.          // character not valid in domain part
  38.          $isValid = false;
  39.       }
  40.       else if (preg_match('/\\.\\./', $domain))
  41.       {
  42.          // domain part has two consecutive dots
  43.          $isValid = false;
  44.       }
  45.       else if
  46. (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
  47.                  str_replace("\\\\","",$local)))
  48.       {
  49.          // character not valid in local part unless
  50.          // local part is quoted
  51.          if (!preg_match('/^"(\\\\"|[^"])+"$/',
  52.              str_replace("\\\\","",$local)))
  53.          {
  54.             $isValid = false;
  55.          }
  56.       }
  57.       if ($isValid && !(checkdnsrr($domain,"MX") ||
  58.  ↪checkdnsrr($domain,"A")))
  59.       {
  60.          // domain not found in DNS
  61.          $isValid = false;
  62.       }
  63.    }
  64.    return $isValid;
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top