Enter an email address and submit. The browser’s type="email" validation is used first, then JavaScript reports the result without leaving the page.
form.addEventListener("submit", (event) => {
event.preventDefault();
if (!email.checkValidity()) {
message.textContent = "Please enter an email address in a valid format.";
email.reportValidity();
return;
}
message.textContent = "The email field passes client-side format validation.";
});
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.