WordPress.org

Ready to get started?Download WordPress

Forums

Restricting email addresses for sign up (4 posts)

  1. Rukas
    Member
    Posted 7 years ago #

    Hey,

    I want to restrict the email domain accepted on sign up. For example, say I only wanted gmail users to sign up, anyone trying to sign up with a different email address to gmail.com would get an error message, however anyone using gmail.com would be fine.

    Any ideas how to do it?

    Thanks in advance.

  2. phuckd
    Member
    Posted 7 years ago #

    otto42's post here will help.

    http://wordpress.org/support/topic/72966

  3. Rukas
    Member
    Posted 7 years ago #

    That one doesnt work because Id have to specify every email domain under the sun I didnt want; but I worked it out already thanks anyway.

  4. gazotem
    Member
    Posted 7 years ago #

    Ok I am fairly new to wordpress and PHP but here is what I did which requires my users who sign up to have @gmail.com in their email address.

    Edit your fuctions-formatting.php file in you wp-includes folder like the following.

    Here is the original block of code.


    function is_email($user_email) {
    $chars = "/^([a-z0-9+_]|\-|\.)+@(([a-z0-9_]|\-)+\.)+[a-z]{2,6}$/i";
    if(strstr($user_email, '@') && strstr($user_email, '.')) {
    if (preg_match($chars, $user_email)) {
    return true;
    } else {
    return false;
    }
    } else {
    return false;
    }
    }

    Here is the edited block.


    function is_email($user_email) {
    $chars = "/^([a-z0-9+_]|\-|\.)+@(([a-z0-9_]|\-)+\.)+[a-z]{2,6}$/i";
    if(strstr($user_email, '@gmail') && strstr($user_email, '.com')) {
    if (preg_match($chars, $user_email)) {
    return true;
    } else {
    return false;
    }
    } else {
    return false;
    }
    }

    That should do it. I do not know how allow only two or three, but I think you were only looking to limit it to one.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.