How to check for a duplicate email address in PHP,

2019-02-07 13:54发布

How can I check for duplicate email addresses in PHP, with the possibility of Gmail's automated labeler and punctuation in mind?

For example, I want these addressed to be detected as duplicates:

         username@gmail.com
        user.name@gmail.com
   username+label@gmail.com
  user.name+label@gmail.com

Despite what Daniel A. White claims: In Gmail, dots at random places before the '@' (and label) can be placed as much as you like. user.name@gmail.com and username@gmail.com are in fact the same user.

7条回答
放荡不羁爱自由
2楼-- · 2019-02-07 14:27

I have extended Zend Validator like this.

<?php
class My_Validate_EmailAddress extends Zend_Validate_EmailAddress
{
    public function isValid($value)
    {
        $valid = parent::isValid($value);
        if ($valid
                && in_array($this->_hostname, array('gmail.com', 'googlemail.com'))
                && substr_count($this->_localPart, '.') > 1) {
            $this->_error(parent::INVALID_HOSTNAME);
            $valid = false;
        }
        return valid;
    }
}

Email with more than one "dot" symbol in gmail address are considered invalid. For some cases this is not logical solution, but that works for me.

查看更多
登录 后发表回答