diff --git a/pages/contact/contact.js b/pages/contact/contact.js index c8b33d5..93a32aa 100644 --- a/pages/contact/contact.js +++ b/pages/contact/contact.js @@ -1,11 +1,24 @@ const sendLetter = document.getElementById("sendLetter"); +const emailInput = document.getElementById("emailInput"); +function addClass(event) { + event.preventDefault(); // Prevents the default form submission behavior -function addClass() { + // Validate email format + const emailValue = emailInput.value.trim(); + if (!isValidEmail(emailValue)) { + alert("Invalid email address"); + return; + } + + // Add the "sent" class if the email is valid document.body.classList.add("sent"); - - } +function isValidEmail(email) { + // Regular expression for a simple email validation + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + return emailRegex.test(email); +} -sendLetter.addEventListener("click", addClass); \ No newline at end of file +sendLetter.addEventListener("click", addClass);