Screening customers via email address

By | March 10, 2010

In the osCommerce forum, someone asked about the possibility of only allowing customers from 1 domain to be able to sign up to their shop. I suppose a typical example might be some shop set up solely for employees of a given company…

Anyway, with a bit of thinking, I came up with the idea of placing the allowed email domains into an array, like this:

$good_emails = array('gmail.com', 'hotmail.co.uk');

Then checking in create_account for the $_POST’d email address and compare against the $good_emails array, and either allow or disallow the account to be created.

$em = explode('@', strtolower($email_address));
if (!in_array($em[1], $good_emails)) {
$error = true;
$messageStack->add('create_account', sprintf(ENTRY_EMAIL_ADDRESS_DISALLOWED, '@' . $em[1]));
}

This works well, but doesn’t give the person trying to create an account any idea that his or her email address is unallowed until they’ve actually filled out the form and submitted – how annoying is that.

So, with a bit more thinking, I used a piece of jQuery to check the inputted email address on the fly. It looks like this;

And by video;

You can easily see that at first I used @gmail.co.uk which is NOT in the allowed list of good emails. I then changed it to @gmail.com and it turned green “on the fly”. A good way to show the potential buyer immediately of any problem.

Had they NOT changed to an allowed email address and gone on to create the account, they would see this;

Notice the error message? I used sprintf to throw back the error message along with the email address they tried to use.

One thought on “Screening customers via email address

Leave a Reply

Your email address will not be published. Required fields are marked *