JBZoo\Utils\Filter::email PHP Method

email() public static method

Validate email
Deprecation: See JBZoo\Utils\Email
public static email ( $email ) : mixed
$email
return mixed
    public static function email($email)
    {
        $email = Str::trim($email);
        $regex = chr(1) . '^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$' . chr(1) . 'u';
        $cleaned = filter_var($email, FILTER_VALIDATE_EMAIL);
        if (preg_match($regex, $email) && $cleaned) {
            return $cleaned;
        }
        return false;
    }

Usage Example

Example #1
0
 /**
  * @param string $email
  * @param string $name
  * @return bool
  */
 public function setFrom($email, $name = null)
 {
     $this->_from = array();
     if ($email = Filter::email($email)) {
         $this->_from[0] = $email;
         $this->_from[1] = $name;
         return true;
     }
     return false;
 }