Skip to content
Snippets Groups Projects
Commit f40c018d authored by Jared Hancock's avatar Jared Hancock
Browse files

validation: Fixup a few email address validations

parent f8b490d0
No related branches found
No related tags found
No related merge requests found
......@@ -140,13 +140,23 @@ class Validator {
/*** Functions below can be called directly without class instance.
Validator::func(var..); (nolint) ***/
function is_email($email) {
if (strpos($email, '@') === false)
return false;
function is_email($email, $list=false) {
require_once 'Mail/RFC822.php';
require_once 'PEAR.php';
return !PEAR::isError(Mail_RFC822::parseAddressList($email));
if (!($mails = Mail_RFC822::parseAddressList($email)) || PEAR::isError($mails))
return false;
if (!$list && count($mails) > 1)
return false;
foreach ($mails as $m) {
if (!$m->mailbox)
return false;
if ($m->host == 'localhost')
return false;
}
return true;
}
function is_phone($phone) {
/* We're not really validating the phone number but just making sure it doesn't contain illegal chars and of acceptable len */
......
......@@ -37,6 +37,9 @@ class TestValidation extends Test {
// Illegal or unsupported
$this->assert(!Validator::is_email('jared r@domain.tld'));
$this->assert(!Validator::is_email('jared'));
$this->assert(!Validator::is_email('jared@'));
$this->assert(!Validator::is_email('@domain.tld'));
$this->assert(!Validator::is_email('@domain.tld, @domain2.tld'));
// Odd cases, but legal
$this->assert(Validator::is_email('jared@host'));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment