Sikau

HTML · Day 12 · about 25 min

Built-in validation

required, min, max, pattern — free checks.

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.

The rest of this lesson

  • How validation feels to usersexplain
  • Patterns without fearexplain
  • Valid?predict
  • Does it pass?predict
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 17 lessons of HTML