HTML provides built-in validation through attributes — the browser checks input before the form submits, with no JavaScript needed for the basics.
Validation attributes
<input type="text" required minlength="2" maxlength="50" /><input type="email" required /> <!-- must be a valid email --><input type="number" min="0" max="100" step="5" /><input type="text" pattern="[0-9]{6}" title="6 digits" /> <!-- regex -->
Client + server
Key takeaways
- 01HTML attributes give built-in validation: required, minlength/maxlength, min/max, pattern.
- 02The browser checks these before submit, with no JavaScript needed.
- 03pattern uses a regex; type="email"/"url" validate formats.
- 04Never trust client validation alone — always re-validate on the server.
