HTML
html/no-number-for-codes
Codes made of digits (postal codes, card numbers, one-time codes, PINs) use type text with inputmode numeric, not type number.
umiarkowanastatycznefe-forms
Dlaczego
type="number" is for quantities. On a postal code or card number it removes leading zeros, accepts e and -, can change the value when the person scrolls over the focused field, and shows spinner buttons that make no sense. The HTML standard itself says the number state is not for such values.
Poprawka
Use type="text" with inputmode="numeric" for the digit keyboard, the right autocomplete token (postal-code, cc-number, one-time-code) and, when the format is fixed, pattern with a visible hint. Keep type="number" for amounts, ages and counts.
Przykłady
<!-- bad -->
<input id="zip" name="zip" type="number">
<!-- good -->
<input id="zip" name="zip" type="text" inputmode="numeric" autocomplete="postal-code">Źródła
Fakty
- Identyfikator
html/no-number-for-codes- Waga
- umiarkowana
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
htmlangularvuesvelteastrojsx- Uczy jej skill
fe-formsNative forms and validation- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain html/no-number-for-codes