Native Form Validation

HTML provides native validation attributes including required, minlength, maxlength, min, max, pattern, and type-specific constraints. Native validation improves basic client-side feedback but must not replace server-side validation.

Client Validation Is Not Security

Attackers can bypass browser validation. Always validate and sanitize untrusted input on the server.

Validated Form
<form>\n  <label for="username">Username</label>\n  <input id="username" name="username" required minlength="3" maxlength="20">\n\n  <label for="age">Age</label>\n  <input id="age" name="age" type="number" min="18" max="100" required>\n\n  <button>Submit</button>\n</form>
💡 The browser can prevent submission when the controls violate their declared constraints.
Key Takeaways
  • Native validation improves user experience.
  • Server-side validation is still required for security and data integrity.
Knowledge Check

Which attribute makes an input mandatory?