Checks without JavaScript
Browsers can check answers before a form is sent: is this field filled in? Is that a real email? Is the number in range? A few attributes give you form validation for free, with messages in the visitor's own language.
Validation attributes
- required — must not be empty.
- minlength / maxlength — text length.
- min / max — number and date ranges.
- pattern — a regular expression the whole value must match.
- Buttons: type="submit" sends, type="reset" clears, type="button" does nothing by itself (for JavaScript).
Browser checks help visitors, but anyone can bypass them. Always check data again on the server too.