WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hii i want to that whenever any user register at my wordpress that just accepet email of specific host for example if I want to accept only User register with username@gmail.com this email format otherwise that show some error that you can only register with @gmail.com so how to apply this condition and in which file thanks

share|improve this question
up vote 2 down vote accepted

I think the User Domain Whitelist plugin is exactly what you want:

The User Domain Whitelist/Blacklist plugin limits user registration to only registrants with an email address from the domain white list below OR prevents registrants with an email address from the domain black list below from registering.

share|improve this answer
Thanks very easy solution :) – realcoder Nov 11 '11 at 10:15

Actually, this is a validation question, not really a WordPress question. You can add a JavaScript file that checks the value of the email field against @gmail.com on submission and either permits the form to submit or alerts the user to an error.

For example, this script would do what you want ...

jQuery(document).ready(function($) {
    $('#registerform').find(':submit').click(function(e) {
        if( ! isGmail( $('#user_email').val() ) ) {
            e.preventDefault(); // Prevent the form from submitting
            alert('You can only register with an @gmail.com email address!');
            return false;

function isGmail( address ) {
    return address.indexOf("@gmail.com", this.length - 10) !== -1;
share|improve this answer
Thanks For helping – realcoder Nov 11 '11 at 10:15

You can use the register_post hook to check if the email domain is in your whitelist and if not just add an error which will tell the user to use an email from your whitelist, something like:

function is_valid_email_domain($login, $email, $errors ){
    $valid_email_domains = array("gmail.com","yahoo.com");// whitelist
    $valid = false;
    foreach( $valid_email_domains as $d ){
        $d_length = strlen( $d );
        $current_email_domain = strtolower( substr( $email, -($d_length), $d_length));
        if( $current_email_domain == strtolower($d) ){
            $valid = true;
    // if invalid, return error
    if( $valid === false ){
        $errors->add('domain_whitelist_error',__( '<strong>ERROR</strong>: you can only register using gmail or yahoo emails' ));

add_action('register_post', 'is_valid_email_domain',10,3 );
share|improve this answer
Thanks Brother Nice Answer :) – realcoder Nov 11 '11 at 10:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.