-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from AbhineshJha/Contactformfixin
Fixed the contact Gmail input section
- Loading branch information
Showing
1 changed file
with
17 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
sendLetter.addEventListener("click", addClass); |