问题
In past many years I have registered on various applications and platforms hosted online or offline.
Why white-spaces are not allowed in User Names as spaces are very natural to names and most of the computing systems can handle them efficiently.
(Many people can raise similar questions about other special characters which are illegal. But their case is far more understandable as they are not even natural to real world naming schemes. And surely!)
回答1:
One subtle problem related to spaces in user names is that the space character is "invisible" and two consecutive spaces may look very similar to a single space. Errors that arise from entering two instead of one space can be hard to spot and this is one reason to disallow spaces all together.
Some systems may disallow spaces but still allow a non-breaking space. A smart user can use this fact to include a space in his user name.
回答2:
I imagine because some code somewhere is still processing the input as a set of space seperated parameters, much the way the Windows command prompt handles unquoted file names. For example if you were to pass the user name to an external executable process, written in C, where the user name was passed on the command line, it would arrive in the C application as two arguments.
While this mightn't happen much in practice any more, much the same as many special characters, I guess its the reason why its there.
回答3:
I think in reality this is probably one of those conventions that needs to be broken. Most systems now deal with a lot of sophisticated data and are used to correctly processing text which includes spaces. I was delighted to discover that fogbugz (another plug) will accept your email address, your username or your real name as you have entered it as your username when you log on.
This is simply a convention that is still around from the days of 8 letter file names and probably also 8 letter user names. I would suggest you allow it in your web app and let the world follow you. :)
回答4:
The only reason I know of that makes any sense is that if you're parsing tokens on whitespace, putting space in a user name will cause it to fail.
However, I do agree with you: in today's environment, there's probably not a lot of reason to continue doing it, except where legacy compatibility makes sense (*nix, etc).
回答5:
I think because generally its a tendency to trim input field values before they are actually saved, say in Database.
Since we trim off the white spaces and if we allow them in password or user name, you can imagine there will be a big issue if user entered a password as "PWD ".
回答6:
It prevents confusingly similar name combinations e.g. "John Smith" and "JohnSmith". It also makes it easier to automatically recognize names that appear within text.
回答7:
It depends where they're going to be used. Not using spaces in unix user names makes sense for the same reason it makes sense not to use them in unix filenames - they're a pain to type at the command line. That said, unix does allow spaces in user names as well as in filenames.
I can see no reason for things like web apps not to allow spaces.
Actually the thing that annoys me most is web apps not allowing @ in user names. When it's something with millions of users the chances of a name I really want being available is small, so I like to use my email address which at least is guaranteed to be unique.
来源:https://stackoverflow.com/questions/208054/user-names-and-white-spaces