HTML5 & Web APIs (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
What is the HTML Constraint Validation API?
senior LevelCode ExampleFormsSystem DesignHTTP & REST APIs
In Simple Words: Allows custom JavaScript validation while leveraging native browser error reporting:
javascript
const emailInput = document.getElementById('email');
emailInput.addEventListener('input', () => {
if (emailInput.value.endsWith('@disallowed.com')) {
emailInput.setCustomValidity('Corporate addresses not permitted.');
} else {
emailInput.setCustomValidity(''); // Empty string marks field as VALID!
}
emailInput.reportValidity(); // Displays native browser tooltip error
});