HTML can check form fields before the form is sent — no JavaScript needed.
| Attribute | What it checks |
|---|---|
required |
The field cannot be empty |
minlength / maxlength |
Text length |
min / max |
Number or date range |
pattern |
Must match a pattern (regular expression) |
type="email" |
Must look like an email |
placeholder |
A hint shown inside the empty field |
If a field is wrong, the browser shows a message and stops the form.
Important: browser checks are for convenience. Always check data on the server too, because users can bypass browser validation.
Example
Example — Validated sign-up form
HTML
<form>
<input type="text" name="name" placeholder="Full name" required minlength="3"><br><br>
<input type="email" name="email" placeholder="Email" required><br><br>
<input type="tel" name="mobile" placeholder="10-digit mobile"
pattern="[6-9][0-9]{9}" title="Enter a valid 10-digit Indian mobile number" required><br><br>
<input type="number" name="age" placeholder="Age" min="16" max="60"><br><br>
<button type="submit">Register</button>
</form>
Try pressing Register with empty or wrong values.
Try it Now »