Allowing spaces in logical "natural language like" input scenarios should not only be allowed, but encouraged. The name is not JohnDoe but John Doe. And same as one comment says (although trying to oppose to this view, so you can see it goes either way), the name is Experts Exchange, not expertsexchange and certainly not Expert Sex Change. And this is why you should enable spaces in usernames: accuracy and limitation of random occurences. Which doesn't mean random spaces. It means natural language spaces.
Also, keep in mind that clearing randomness applies to everything. I mean, you can sanitize inputs as a secondary step, but you should make very clear that username, with or without spaces, should be used in only one way. Going back to our friend, if he signed as JohnDoe
, then his username will be JohnDoe
, not John Doe
.
Another thing: you can sanitize and filter usernames with these conditions:
- spaces before username
- spaces after username
- repeated spaces
This way, you only allow 1 (one) space. You can also restrict usernames to 2 words, and even offer an username option to the user, like this:
Welcome John Doe, please select your username
- JohnDoe
- John Doe
- or enter username
Finally, there's the usual middle point for your case: you may have one username/login, then have a display name. This is a very common approach, and one you should contemplate if you decide not to use spaces (after all, username is not the same as display name ). Since our good friend is not JohnDoe, nor johndoe69 nor [email protected] , I'd advise to either use spaces in your username OR allow display names selected by the user. Obviously, allowing usernames with spaces is the easier way, but if you don't do this, then use display names
Experts Exchange
, the system will silently translate it intoexpertsexchange
, and the system will direct queries for a user with usernameExpert Sex Change
to my account?