Form Validation

๐ŸŒ HTML5 ๐ŸŸข Chapter 19 of 37 ๐Ÿ“‚ Phase 07: Forms & Input Controls ๐Ÿ“… 2026 Edition
๐Ÿ“Œ Covered in this chapter: Browser Native Validation ยท novalidate Attribute ยท Validity State Object ยท checkValidity() & reportValidity() ยท CSS :valid & :invalid ยท Custom JS Messages
Welcome to Phase 7 (Chapter 19): Form Validation! Validate input data before sending it to your backend using native HTML5 validation and JavaScript's ValidityState API.
1ValidityState API Syntax
HTML + JS โ€” Custom Form Validation โ–ถ Run in HTML Editor
<form novalidate id="myForm">
  <input id="email" type="email" required placeholder="Enter email">
  <button type="button" onclick="validateInput()">Validate</button>
</form>

<script>
  function validateInput() {
    const input = document.getElementById('email');
    if (!input.checkValidity()) {
      alert('Validation Error: Please enter a valid email address!');
    } else {
      alert('Success: Input is valid!');
    }
  }
</script>
OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy & tested on HTML5 Standards ยท Last updated August 2026