• So I just opened another wordpress website, this will be like my fifth more or less. But I ran into a bit of trouble this time since this website is directed to a specific group of people not all of whom are used to creating user accounts on websites and forums. At least 5 out of 30 people had difficulty during registration because they didn’t realize they couldn’t use a space in their username (they were in fact using First Name and Last Name instead of a one word username during registration). And then they were getting locked out of their profiles, they weren’t able to log in after that. I explained to them they shouldn’t use spaces, deleted their profiles, and let them go through registration again. I have also added this snippet to my functions.php:

    add_filter('validate_username' , 'custom_validate_username', 10, 2);
    function custom_validate_username($valid, $username ) {
    		if (preg_match("/\\s/", $username)) {
       			// there are spaces
    			return $valid=false;
    		}
    	return $valid;
    }

    I believe this should be integrated directly into WordPress: why even allow spaces in usernames during registration if it is considered invalid input? If it’s invalid, it shouldn’t be allowed at all, and people should know it. AND there should be some kind of guidance as regards what a “username” is intended to be, explaining that it’s not “first name space last name”…

    • This topic was modified 4 years, 11 months ago by Jan Dembowski.
Viewing 1 replies (of 1 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    In general, WordPress works fine with spaces in usernames. There is specific code to disallow such things in multisite configurations, but for simple single site installs, spaces in usernames works fine.

Viewing 1 replies (of 1 total)
  • The topic ‘prevent username with spaces on registration’ is closed to new replies.