HTML - Form Validation

About

This page is about form validation in HTML.

The javascript counterpart is called the constraint validation API 1).

In short, you set standard HTML attributes that constrain the possible value of form elements.

List of validation rules

  • required
  • min
  • max
  • minLength
  • maxLength
  • pattern
  • validate

Limitations

HTML validation has its limitations.

  • it only works in the browser (not React Native, …)
  • it's hard/impossible to show custom error messages to our user.

Function

  • form.checkValidity() - Returns true if the form's controls are all valid; otherwise, returns false.
  • form.reportValidity() - Returns true if the form's controls are all valid; otherwise, returns false and informs the user.

Documentation / Reference





Discover More
HTML - Form element

form is an element that represents a user-submittable form. When parsed as HTML, a form element's start tag will imply a p element's end tag just before. The pizza order form (taken from the...



Share this page:
Follow us:
Task Runner