-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact.js
43 lines (35 loc) · 1.31 KB
/
contact.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
document.getElementById("contactForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form submission
// Perform form validation
var nameInput = document.getElementById("rehman");
var emailInput = document.getElementById("rehman123@gmail.com");
var messageInput = document.getElementById("hi");
var isValid = true;
if (nameInput.value.trim() === "") {
isValid = false;
nameInput.classList.add("error");
} else {
nameInput.classList.remove("error");
}
if (emailInput.value.trim() === "" || !isValidEmail(emailInput.value)) {
isValid = false;
emailInput.classList.add("error");
} else {
emailInput.classList.remove("error");
}
if (messageInput.value.trim() === "") {
isValid = false;
messageInput.classList.add("error");
} else {
messageInput.classList.remove("error");
}
if (isValid) {
// Perform form submission (you can send the form data to a server using AJAX or any other method)
console.log("Form submitted successfully!");
}
});
function isValidEmail(email) {
// Simple email validation regex
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}