I’ve been reading the Ruby on Rails 3 Tutorial book by Michael Hartl and he doesn’t validate the username in the sample app of the book. Yet so many websites are asking users to register with only alphanumerics and underscores(not always allowed even).
I’ve searched for a while both on google and stack_overflow but only found huge amount of people asking how to validate username in the above manner.
Gee, why do we need to do it in the first place then?
Once reason I can think of is to ensure they are URL friendly. Any website that has a user resource, and uses the username in the URL instead of the ID, will require a URL-safe username.
Any website that requires a username but doesn’t use it as a resource probably shouldn’t require a username to begin with (use email address for login instead).
EDIT:
To answer your comment: “The space character is unsafe because significant spaces may disappear and insignificant spaces may be introduced when URLs are transcribed or typeset or subjected to the treatment of word-processing programs.”
As per RFC 1738. This document also describes why other characters are unsafe.