Source of file EmailRule.php
Size: 1,136 Bytes - Last Modified: 2017-11-08T13:54:24+00:00
/home/travis/build/bluzphp/framework/src/Validator/Rule/EmailRule.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 | <?php /** * Bluz Framework Component * * @copyright Bluz PHP Team * @link https://github.com/bluzphp/framework */ declare(strict_types=1); namespace Bluz\Validator\Rule; /** * Check for email * * @package Bluz\Validator\Rule */ class EmailRule extends AbstractRule { /** * @var string error template */ protected $description = 'must be a valid email address'; /** * @var bool check DNS record flag */ protected $checkDns; /** * Setup validation rule * * @param bool $checkDns */ public function __construct($checkDns = false) { $this->checkDns = $checkDns; } /** * Check input data * * @param mixed $input * * @return bool */ public function validate($input): bool { if (is_string($input) && filter_var($input, FILTER_VALIDATE_EMAIL)) { list(, $domain) = explode('@', $input, 2); if ($this->checkDns) { return checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A'); } return true; } return false; } } |