HTML
html/constraint-attr-type
Validation attributes match the input type (pattern and maxlength on text-like types, min, max and step on number and date types).
umiarkowanastatycznefe-forms
Dlaczego
Each constraint attribute applies only to some input types; on any other type it is ignored without a warning. pattern and maxlength on type="number", or min and max on a text field, look like validation in review but never run, so bad values reach the server.
Poprawka
Use the attributes the type supports: for numbers and dates min, max and step; for text, email, URL, phone, search and password pattern, minlength and maxlength. For a code of digits, switch to type="text" inputmode="numeric" with pattern. Always validate on the server as well.
Przykłady
<!-- bad -->
<input id="qty" type="number" maxlength="2">
<!-- good -->
<input id="qty" type="number" min="1" max="99">Źródła
Fakty
- Identyfikator
html/constraint-attr-type- 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/constraint-attr-type