mercredi 15 juin 2022

I've been trying to make a validation for phone number where it will alert the user if they did not follow the format. How do I do it?

var form = document.getElementById('form-body')

var error = []

form.addEventListener('submit', function(e){ e.preventDefault();

var name = document.getElementById('name');
var phone = document.getElementById('phone');
var email = document.getElementById('email');
var bday = document.getElementById('bday');

if (phone.value !== [0]{1}?[9]{1}?[0-9]{9})
    alert('Follow the correct format (09XXXXXXXXX)')    

})

Aucun commentaire:

Enregistrer un commentaire