Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Invalidate username if it contains @ symbol

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. 🙂

Related Posts:

  1. How to login with email only no username?
  2. What are the differences between wp_users and wp_usermeta tables?
  3. How can I send a welcome email to a user AFTER they login for the first time?
  4. Customize wp_new_user_notification_email()
  5. Login email after registration never sent or received
  6. Right practice to edit WP reset password email
  7. Private page protected with username and password
  8. How can I change the email sender name from wordpress to (myblogname) on the “lost password” email?
  9. Lock out all WordPress Administrators except two specific users
  10. Generate email on meta value update
  11. Why is wp-login trying to send an email?
  12. Display first name instead of username
  13. Input sanitation
  14. WordPress not logged in locally with correct username and password
  15. Sending new registration meta values to admin by email
  16. Log in with email but no password
  17. Updated : how to make email optional while user registration using default wordpress form
  18. Make WordPress User Name be the Company Name when Registering (not the default ‘first name’ last name’ email address’)
  19. WordPress does not send email confirmation to newly registered users
  20. confirmation email is send from my local host registration of a user but mail will not display in there email account?
  21. User login without username, only password
  22. Cannot login with correct username and password anymore
  23. Cant login, Password MUST be reset error, after reset
  24. Username character requirements
  25. In Django, how do I know the currently logged-in user?
  26. Can I programmatically login a user without a password?
  27. Can’t log in: “ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.”
  28. Is there any way to rename or hide wp-login.php?
  29. How can I redirect user after entering wrong password?
  30. Increase of failed login attempts, brute force attacks? [closed]
  31. Login page ERROR: Cookies are blocked due to unexpected output
  32. Separate registration and login for different roles
  33. SSO / authentication integration with external ‘directory service’
  34. Preventing session timeout
  35. How reduce wordpress login session timeout time?
  36. How to prefill WordPress registration with social details
  37. Check for correct username on custom login form
  38. Disallow user from editing their own profile information
  39. I can’t access my site via wp-admin
  40. ‘Password field is empty’ error when using autofill in Chrome
  41. Removing username from the ‘wordpress_logged_in’ cookie
  42. How to show ‘login error’ and ‘lost password’ on my template page?
  43. What is $interim_login?
  44. Custom login form
  45. How to prefill the username/password fields on the login page
  46. wp_signon returns user, but the user is not logged in
  47. Adding extra authentication field in login page
  48. Prevent wp_login_form() from redirecting to wp-admin when there are errors
  49. Redirect user using the ‘wp_login_failed’ action hook if the error is ’empty_username’ or ’empty_password’
  50. wp_signon() does not authenticate user guidance needed
  51. What exactly is ReAuth?
  52. Login members using web services
  53. Make my wordpress blog remember my login “forever”
  54. How to check in timber if user is loggedin?
  55. How do I change the language of only the login page?
  56. Disable WordPress 3.6 idle logout / login modal window / session expiration
  57. Stop WordPress from logging me out (need to keep me logged in)
  58. Woocommerce registration page [closed]
  59. How to disable autocomplete on the wp-login.php page
  60. Share login data/cookies between multiple installations
  61. Synchronize WordPress user accounts across multiple domains and installations without using WordPress MU
  62. How to pass users back and forth using session data?
  63. How do I change the logo on the login page?
  64. Why does WordPress hide the reset password key from the URL?
  65. Is it possible to sign in with user_email in WordPress?
  66. Editing ‘Password Reset’ E-mail
  67. How to use current_user_can()?
  68. Avoid to load default WP styles in login screen
  69. WordPress registration message
  70. How to fake a WordPress login?
  71. how to display the wordpress login and register forms on a page?
  72. Does wp_logout_url() destroy a session? (Logging out question)
  73. Can not login with correct username and password
  74. Website Visible only to Registered users
  75. How can i increase the login expiration length?
  76. How do I use add_action from a class method?
  77. How to remove the WordPress logo from login and register page?
  78. How can I add a custom script to footer of login page?
  79. Brute force attack?
  80. Need to execute a cron job
  81. How can I create a separate blog that is private?
  82. How to keep always logged in development environment
  83. Add Confirm Password field in wp-login.php Password Reset page
  84. Integrate recaptcha and wp_signon – what is needed?
  85. Stop users from logging in from multiple locations
  86. I want to disable E-Mail verifcation / activation when a user signs up for my WordPress site
  87. custom login page redirect to logged in user profile page
  88. Email address or username used to login in wordpress
  89. How do I check if a post is private?
  90. Email as Username in registration
  91. How can I modify the default reset (lost) password email text?
  92. Front-end login: Redirect user to the post they had created
  93. Receiving “This content cannot be displayed in a frame” error on login page
  94. My login form does not work
  95. Programmatically log in a wordpress user
  96. Action wp_login_failed not working if only one field is filled out
  97. Getting “Cookies are blocked or not supported by your browser” on login page
  98. What is the purpose of logging out after WordPress upgrade?
  99. Is it alright for two people to simultaneously be logged into a WP site as administrator?
  100. wp-login.php redirecting to HTTPS
Categories login Tags email, login, sanitization, username
How to add options to the plugin page?
Custom pagination code is not working

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress