Checking similar gmail email ids

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
leon_nerd
Forum Commoner
Posts: 25
Joined: Tue Aug 21, 2007 1:20 pm

Checking similar gmail email ids

Post by leon_nerd »

Hi Guys,

I am working on an application where we need to have each user input unique email id. Now, the problem is with gmail IDs. In gmail username@gmail is same as user.name@gmail.com which is again same as use.r.name@gmail.com.

Now, how to make sure that only one of a kind of email id is allowed. I am storing the email IDs in the database. Should, I be using a query involving LIKE ? Please suggest.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Checking similar gmail email ids

Post by Jonah Bron »

Before storing them in the database, or querying for them, strip out all dots from the local part of the email address.

Code: Select all

$email = 'john.doe@gmail.com';
$localLength = strpos($email, '@');
$email = substr_replace($email, str_replace('.', '', substr($email, 0, $localLength)),  0, $localLength);
// $email == 'johndoe@gmail.com'
(cite for that Gmail-specific normalization here: http://en.wikipedia.org/wiki/Email_addr ... malization)
Post Reply