Skip to content
  1. Extras
  2. FetchIt
  3. Validation

Validation ​

Client-side checks catch mistakes before sending, so the visitor does not wait for the server to learn about a typo in the e-mail. All the examples follow one scheme: a fetchit:before handler checks the fields, shows the errors with setError and cancels the submission with preventDefault().

Important!

Client-side validation is not secure and should only be used to improve user experience.

  • Browser validation — the required, type and pattern attributes, no libraries
  • Zod — the most popular schema library, with the light zod/mini build for the browser
  • Valibot — a schema built from small functions, 2–3 KB
  • yup — a schema, if the project already has yup
  • validator.js — ready-made checks for phone numbers, e-mails and other strings; complements any option above

FetchIt removes the errors by itself before each submission and from a field the visitor starts editing, so the handler does not need to clear them.