document.addEventListener('DOMContentLoaded', function () { const form = document.querySelector('.wpcf7 form'); // Contact Form 7 form selector if (form) { form.addEventListener('submit', function () { const phoneField = form.querySelector('.phone-field'); // Target phone field by class if (phoneField) { let phone = phoneField.value.replace(/\D/g, ''); // Remove all non-numeric characters if (phone.length === 10) { // Format the phone number as 123-456-7890 phoneField.value = phone.replace(/(\d{3})(\d{3})(\d{4})/, '$1-$2-$3'); } } }); } });