You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
766 B
20 lines
766 B
function validateForm() {
|
|
const phoneInput = document.getElementById('phone');
|
|
const contactError = document.getElementById('contact-error');
|
|
let isValid = true;
|
|
|
|
// Clear any previous error messages
|
|
contactError.textContent = "";
|
|
|
|
// Validate Phone Number
|
|
const phoneCriteria = /^\d{10}$/; // Ensure exactly 10 digits
|
|
if (!phoneCriteria.test(phoneInput.value)) {
|
|
contactError.textContent = "Phone number must be exactly 10 digits.";
|
|
phoneInput.classList.add("border-red-500"); // Add red border if invalid
|
|
isValid = false;
|
|
} else {
|
|
phoneInput.classList.remove("border-red-500"); // Remove red border if valid
|
|
}
|
|
|
|
return isValid; // Return false to prevent submission if validation fails
|
|
} |