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 = $('
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!