Skip to content

Instantly share code, notes, and snippets.

Last active January 19, 2023 21:52
What would you like to do?
Providing custom error messages for built-in HTML5 form validation
<!DOCTYPE html>
<html lang="en">
<title>Form Validation</title>
body { padding: 10px; }
<label for="name">Name</label>
<input type="text" id="name" name="name" required />
<button type="submit">Submit</button>
const input = document.querySelector('input[name="name"]');
input.addEventListener('invalid', function (event) {
if ( {'Please tell us how we should address you.');
input.addEventListener('change', function (event) {'');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment