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).
fullstack ruleP1universalStack: javascript
regexvalidationnamingcorrectness
Use + not * when at least one character is required, and name validators to match their semantics
A trailing * quantifier matches the empty string, so it validates as true for empty input; use + when one or more characters are required, and name the validator to reflect whether empty is allowed.
PR: hegnar-web · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | const isNumber = (value?: string) => /^[0-9]*$/.test(value ?? ''); |
| 2 | // matches '' as a valid number |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | // require at least one digit |
| 2 | const isNumber = (value: string) => /^[0-9]+$/.test(value); |
| 3 | // or be explicit that empty is allowed |
| 4 | const isEmptyOrValidNumber = (value?: string) => /^[0-9]*$/.test(value ?? ''); |
Explanation (EN)
Objašnjenje (HR)