Lesson 18 / 30
Basic Validation
Validate input in the browser with required, minlength and pattern, and re-check on the server.
required, pattern, min, max
The browser blocks submission and shows a message until these constraints are met.
<input type="text" required minlength="3">
<input type="number" min="1" max="10">
<input type="text" pattern="[A-Za-z]+" title="Letters only">Not a security fence
HTML validation runs in the browser and can be bypassed — always re-validate on the server too.
Quick check: Which attribute makes a field mandatory before submit?
- placeholder
- readonly
- required
- autofocus
Answer
required — `required` blocks form submission until that field has a value.