/** * Check an email address for correct format. * * @param string email address * @param boolean strict RFC compatibility and valid domain with MX * @return boolean */ public static function email($email, $strict = FALSE) { //strict validation if ($strict === TRUE) { //check the RFC compatibility and MX return parent::email($email, TRUE) ? Valid::email_domain($email) : FALSE; } else { return parent::email($email); } }
/** * Check an email address for correct format. * * @param string email address * @param boolean valid domain with MX and not disposable email * @return boolean */ public static function email($email, $strict = FALSE) { //get the email to check up, clean it $email = filter_var($email, FILTER_SANITIZE_STRING); // 1 - check valid email format using RFC 822 if (filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) { return FALSE; } //strict validation, MX domain and valid domain not disposable if ($strict === TRUE) { return Valid::email_domain($email); } // wow actually a real email! congrats ;) return TRUE; }
/** * Tests Valid::email_domain() * * Validate the domain of an email address by checking if the domain has a * valid MX record. * * Test skips on windows * * @test * @dataProvider provider_email_domain * @param string $email Email domain to check * @param boolean $correct Is it correct? */ public function test_email_domain($email, $correct) { if (!$this->hasInternet()) { $this->markTestSkipped('An internet connection is required for this test'); } if (!Kohana::$is_windows or version_compare(PHP_VERSION, '5.3.0', '>=')) { $this->assertSame($correct, Valid::email_domain($email)); } else { $this->markTestSkipped('checkdnsrr() was not added on windows until PHP 5.3'); } }