This content originally appeared on text/plain and was authored by ericlaw
Leading and trailing whitespace are generally invisible. Humans are bad at dealing with things they can’t see.
If your system accepts textual codes, or any other human-generated or human-mediated input, you should trim whitespace, whether it’s leading, trailing, or inline (if not meaningful).
// Trim leading and trailing whitespace
$('inputCode').value = $('
inputCode
').value.trim();
It’s downright silly that web-first companies with market capitalizations in the $Billions have not yet figured out this simple trick for improving their applications. Instead, we end up with garbage error messages like this one:
Or this one, from the most valuable company in history:
Related: Browsers can do better here too. On paste into a length-limited control, we should probably trim leading whitespace first if needed to respect the limit.
Improve the world: Trim harmful whitespace!
-Eric
This content originally appeared on text/plain and was authored by ericlaw

ericlaw | Sciencx (2022-01-10T19:32:08+00:00) Trim Your Whitespace. Retrieved from https://www.scien.cx/2022/01/10/trim-your-whitespace/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.