Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WordPress Registration Email Validation

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #33163
    jlau
    Member

    Hi there,

    I’ve created a custom registration page using Registration Plus Redux and I need to create a more specific email validation. Basically I need to only allow ‘ac.uk’ email addresses to register. But I need people to be able to register with emails such as:

    [email protected]

    and also

    [email protected]

    Any help would be greatly appreciated. I have tried to use a plugin called ’email validation’ or something similar, but it hasn’t been updated in over a year and either doesn’t work or isn’t compatible with registration plus redux.

    Thanks in advance

    #72584
    ddliu
    Member

    Hi jlau, I guess you are meaning “how to validate such an email address”.

    Basically you may have a regular expression to do this in PHP, and maybe following code will work for you:


    if(preg_match('#^[a-z0-9_.-]{1,50}@([a-z0-9_-].){0,5}ac.uk$#i',$email)){
    echo "Yeah, you have an ac.uk email address!";
    }
    else{
    echo "Oops, your email address is not valid or is not an ac.uk email address!";
    }
    #81878
    jlau
    Member

    Hi ddliu,

    Thanks a lot for the reply. I really appreciate it. I’m not super comfortable with php/wordpress. So where would I put this code in my theme to get it to affect my registration?

    If it helps my website is http://www.heruni.com

    #81889
    ddliu
    Member

    I don’t think it’s in the theme, you may change it here:
    file wp-login.php, find function “register_new_user”, find code:


    // Check the e-mail address
    if ( $user_email == '' ) {
    $errors->add( 'empty_email', __( 'ERROR: Please type your e-mail address.' ) );
    } elseif ( ! is_email( $user_email ) ) {
    $errors->add( 'invalid_email', __( 'ERROR: The email address isn’t correct.' ) );
    $user_email = '';
    } elseif ( email_exists( $user_email ) ) {
    $errors->add( 'email_exists', __( 'ERROR: This email is already registered, please choose another one.' ) );
    }

    add following code at the end of the if…else… scope:


    elseif (!preg_match('#[@.]ac.uk$#i', $user_email){
    $errors->add( 'invalid_email', __( 'ERROR: Only "ac.uk" email address allowed.' ) );
    $user_email = '';
    }

    Maybe there is a way to change it in the theme? I have no idea, don’t know that much.

    #82192
    jlau
    Member

    Thanks a lot! It worked well :)

    If anyone else wants to use this code. Theres a right bracket missing after $user_email.

    Does anyone know how to change this from the theme?

    #248899
    Anonymous
    Inactive

    Hi , its very easy to verify Email validation. For Email Validation you can simply go through this site http://www.melissadata.in/cloud-services/global-email-cloud-service

    #248901
    Shikkediel
    Participant

    One link might be useful if it’s relevant enough. But three in a row without anything else and I’d say you’re a spammer.

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘Back End’ is closed to new topics and replies.