Skip to content

Commit

Permalink
"Added form validation to contact form"
Browse files Browse the repository at this point in the history
  • Loading branch information
faris-zak committed Jul 11, 2024
1 parent b339d86 commit 8711618
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions assets/js/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ userImage.addEventListener('mouseout', () => {
userImage.style.maxWidth = '500px';
});

document.querySelector('.contact-form').addEventListener('submit', function(event) {
var name = document.getElementById('name').value;
var email = document.getElementById('email').value;
var subject = document.getElementById('subject').value;
var message = document.getElementById('message').value;

if (!name || !email || !subject || !message) {
alert('Please fill in all fields');
event.preventDefault();
} else if (!validateEmail(email)) {
alert('Please enter a valid email address');
event.preventDefault();
}
});

function validateEmail(email) {
var re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return re.test(email);
}

shape.addEventListener('mouseover', () => {
shape.style.opacity = '0.5';
shape.style.transform = 'translateY(280px)';
Expand Down

0 comments on commit 8711618

Please sign in to comment.