forked from PriyaGhosal/BuddyTrail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.js
37 lines (30 loc) · 1.13 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
document.getElementById('contactForm').addEventListener('submit', function(e) {
e.preventDefault();
// Basic form validation
let fullname = document.getElementById('fullname').value;
let email = document.getElementById('email').value;
let phone = document.getElementById('phone').value;
let message = document.getElementById('message').value;
if (!fullname|| !email || !phone || !message) {
alert('Please fill in all fields');
return;
}
if (!isValidEmail(email)) {
alert('Please enter a valid email address');
return;
}
if (!isValidPhone(phone)) {
alert('Please enter a valid phone number');
return;
}
// If validation passes, you can submit the form data to your server here
console.log('Form submitted:', { fullname, email, phone, message });
alert('Thank you for your message. We will get back to you soon!');
this.reset();
});
function isValidEmail(email) {
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}
function isValidPhone(phone) {
return /^\+?[\d\s-]{10,}$/.test(phone);
}