HTML Form Validation
Use native validation and understand why server validation is essential.
Category: HTML | Lesson: 14 of 40
Native validation
<form action="/register" method="post">
<label for="email">Email address</label>
<input id="email" name="email" type="email" required>
<label for="password">Password (at least 8 characters)</label>
<input id="password" name="password" type="password" minlength="8" required>
<button type="submit">Register</button>
</form>
Validation attributes
required, min, max, step, minlength, maxlength, and input types such as email and url provide browser validation.
Security rule
Client-side validation can be bypassed. Validate and sanitize input on the server as well. Never trust browser-submitted data.
Accessible errors
Explain what is wrong and how to fix it. Associate custom error text with the relevant control, and do not rely on colour alone.
Practice
Add required email validation, minimum password length, and numeric range constraints. Test invalid values.
Want to learn this professionally?
Explore practical IT training at Cyber Code Academy.
View Academy Courses