Skip to content

Commit

Permalink
git commit
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-peter-kamvabingu committed Dec 6, 2024
1 parent f084031 commit a1d6b1c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
document.querySelector('form').addEventListener('submit', function (e) {
e.preventDefault();

// Input values
const name = document.querySelector('.c-name').value.trim();
const phone = document.querySelector('.c-phone').value.trim();
const email = document.querySelector('.c-email').value.trim();
const message = document.querySelector('.c-message').value.trim();

// Error messages
const messageName = document.querySelector('.f-name');
const messagePhone = document.querySelector('.f-phone');
const messageEmail = document.querySelector('.f-email');
const submitFeedback = document.querySelector('.submit-feedback');

// Validation Functions
const isEmail = (mail) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(mail);
const isName = (name) => /^[a-zA-Z\s]+$/.test(name);
const isEmail = (mail) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(mail); // Simple email regex
const isName = (name) => /^[a-zA-Z\s]+$/.test(name); // Matches letters and spaces
const isPhoneNumber = (number) => /^\d+$/.test(number); // Matches any numeric value

let isValid = true;

Expand All @@ -25,10 +27,9 @@ document.querySelector('form').addEventListener('submit', function (e) {
messageName.style.display = 'none';
}

// Phone Validation (allows any numbers)
if (!phone || isNaN(phone)) {
// Phone Validation (Any numeric phone number)
if (!isPhoneNumber(phone)) {
messagePhone.style.display = 'block';
messagePhone.textContent = '*Please enter a valid phone number';
isValid = false;
} else {
messagePhone.style.display = 'none';
Expand Down

0 comments on commit a1d6b1c

Please sign in to comment.