Ejemplo n.º 1
0
 /**
  * Checks if value passed is in a valid email format.<p>
  *
  * @param  object  $value     any type of value that needs to be checked.
  * @param  string  $message   name of value being passed, used in error message.
  * @param  bool    $letReturn will determine if it throws an PHException or returns true.
  * @return bool will either return false if not and on success will return true if allowed.
  */
 public function isEmail($value, $letReturn = false)
 {
     if (!EmailAddressValidatorUtil::check_email_address($value)) {
         if (!$letReturn) {
             ErrorsUtil::error("Email is not in a valid email format.", ServiceCodes::INVALID_EMAIL_ERROR, null);
         } else {
             return false;
         }
     } else {
         return true;
     }
 }
 /**
  * Checks email section after "@" symbol for validity
  * @param   strDomainPortion     Text to be checked
  * @return  True if domain portion is valid, false if not
  */
 protected static function check_domain_portion($strDomainPortion)
 {
     // Total domain can only be from 1 to 255 characters, inclusive
     if (!EmailAddressValidatorUtil::check_text_length($strDomainPortion, 1, 255)) {
         return false;
     }
     // Check if domain is IP, possibly enclosed in square brackets.
     if (preg_match('/^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])' . '(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}$/', $strDomainPortion) || preg_match('/^\\[(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])' . '(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}\\]$/', $strDomainPortion)) {
         return true;
     } else {
         $arrDomainPortion = explode('.', $strDomainPortion);
         if (sizeof($arrDomainPortion) < 2) {
             return false;
             // Not enough parts to domain
         }
         for ($i = 0, $max = sizeof($arrDomainPortion); $i < $max; $i++) {
             // Each portion must be between 1 and 63 characters, inclusive
             if (!EmailAddressValidatorUtil::check_text_length($arrDomainPortion[$i], 1, 63)) {
                 return false;
             }
             if (!preg_match('/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|' . '([A-Za-z0-9]+))$/', $arrDomainPortion[$i])) {
                 return false;
             }
         }
     }
     return true;
 }