Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
frontend ruleP2universalStack: JavaScript
formsinputvalidation
Trim and normalize free-text user input before using it
Trim (and normalize, e.g. strip formatting separators) text the user types or pastes before validating, comparing or sending it. Pasted values routinely carry leading/trailing whitespace and formatting characters that make an otherwise-valid input fail.
PR: profico-org-corpus batch2 (all stacks/products)Created: Jul 26, 2026
Bad example
Old codets
| 1 | const code = input.value; // " 1234-1234 " |
| 2 | redeem(code); // backend rejects it |
Explanation (EN)
A stray space from pasting silently invalidates a correct code.
Objašnjenje (HR)
Good example
New codets
| 1 | const code = input.value.trim().replace(/-/g, ''); |
| 2 | redeem(code); |
Explanation (EN)
Trimming and normalizing the expected format makes paste-with-whitespace work.
Objašnjenje (HR)