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

I would like to let the user login either using username or email.

The only way to find the email is by detecting @ symbol using strpos.

However WordPress allow @ symbol in username too.

Can someone help me to invalidate username if it contains @ symbol in it..

share|improve this question
up vote 2 down vote accepted

In a multi-site installation it is 'wpmu_validate_user_signup':

add_filter( 'wpmu_validate_user_signup', 'wpse_77904_mu_no_at_in_username' );

function wpse_77904_mu_no_at_in_username( $user )
    if ( FALSE !== strpos( $user['user_name'], '@' ) )
        $user['errors']->add('user_name',  __( 'That username is not allowed.' ) );

    return $user;

On single-site it is 'validate_username':

add_filter( 'validate_username', 'wpse_77904_no_at_in_username', 10, 2 );

function wpse_77904_no_at_in_username( $valid, $username )
    if ( FALSE !== strpos( $username, '@' ) )
        return FALSE;

    return $valid;

Caveat: both not tested. :)

share|improve this answer
Great.. It works :) – Giri Jan 1 '13 at 19:14

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.