Form validation is the process of verifying that data submitted through a form meets expected rules, such as required fields, valid email format, length limits or numeric ranges, before it is accepted.
Why it matters
Validation catches typos early and protects data quality, but it has two distinct layers. Client-side validation, using HTML attributes or JavaScript, gives instant feedback and reduces round trips. It can be bypassed trivially, so it is a convenience, never a security control. Server-side validation is the authoritative check and defends against malformed or malicious input such as injection attempts. Good messages say what is wrong and how to fix it.
Example
<form>
<label>Email <input type="email" name="email" required></label>
<label>Age <input type="number" name="age" min="18" max="120"></label>
<label>Code <input name="code" pattern="[A-Z]{3}-\d{4}"
title="Format: ABC-1234"></label>
<button>Send</button>
</form>
The browser blocks submission and shows a message if a field is missing or fails its constraint. The :invalid pseudo-class can style these fields.
Common mistakes
- Relying only on client-side checks.
- Rejecting valid input, such as plus signs in emails or names with apostrophes.
- Vague errors like "Invalid input".
- Showing errors before the user has finished typing.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.