Skip to content

Commit

Permalink
Created emailValidator.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugunth140 authored Oct 19, 2024
1 parent d1be8bf commit 40ab327
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions emailValidator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function validateEmail(email) {
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return re.test(String(email).toLowerCase());
}
document.addEventListener("DOMContentLoaded", () => {
const form = document.querySelector("form");
form.addEventListener("submit", function(event) {
const emailInput = document.querySelector("input[name='username']");
if (!validateEmail(emailInput.value)) {
alert("Please enter a valid email address.");
event.preventDefault();
}
});
});

0 comments on commit 40ab327

Please sign in to comment.