-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
34 lines (28 loc) · 1.01 KB
/
script.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
document.addEventListener('DOMContentLoaded', function() {
const contactForm = document.getElementById('contactForm');
contactForm.addEventListener('submit', function(event) {
event.preventDefault();
if (validateForm()) {
alert('Form submitted successfully!');
contactForm.reset();
}
});
function validateForm() {
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const message = document.getElementById('message').value;
if (name.trim() === '' || email.trim() === '' || message.trim() === '') {
alert('Please fill in all fields.');
return false;
}
if (!isValidEmail(email)) {
alert('Please enter a valid email address.');
return false;
}
return true;
}
function isValidEmail(email) {
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailPattern.test(email);
}
});