9

I want to propose a new guideline in our company to disallow leading or trailing spaces in any user input (web forms).

Is there any valid scenario where you want to allow leading or trailing spaces in user input?


One field that you could argue allowing this could be a password field, but I would disallow it for simplicities sake

1
  • 2
    Do not disallow anything in a password input field for any reason: it's a signal to your users that you don't know how to handle passwords correctly. Take any string, hash it, and store it as whatever (usually a hexadecimal string representation).
    – msanford
    Commented Aug 9, 2017 at 12:59

2 Answers 2

9

Depends on the type of form input:

Usernames/Emails

Trim away. Especially if you accept mobile input, as some auto-complete keyboards insert a trailing space after emails.

Passwords

As mentioned by others, do not trim. Treat spaces like any other alphanumeric/symbolic character.

Text Paragraph Entry

Just be careful here on implementation, as some languages' trim methods remove tabs and newlines. This may break formatted text.

My answer here refers to "trimming", which in this case means the removal of spaces after the input has been received. This could also be achieved with client-side validation.

4

I wouldn't blame the user with a validation error if he types a space as the last (or first) character of an input field: if you trim the input once submitted, there won't be any problem.

I cannot think of any common scenario where the input text won't be trimmed. Passwords would be an edge case. There are some input field that won't accept a space as a valid character, such as E-mail address field or numeric input, but this is an other story.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.