im having trouble using this function for form validation. What im trying to do is test if the input is empty, then put "Please fill in form", or if it has something other than letters put " Please use only letters" then of course if all that matches pass true. - What keeps happening is that i only get Please use only letters, no matter what.
function validateName(x){
var re = /[A-Za-z -']$/;
if ((x.value) == ""){
(x.style.background) = '#e35152';
(x.style.color) = 'white';
(x.value) = "Please Fill in First Name";
return false;
}else {
if (((x.value) != "") || (!re.test(x.value))){
(x.style.background) = '#e35152';
(x.style.color) = 'white';
(x.value) = "Please Use Only Letters";
return false;
}else {
(x.style.background) = 'white';
(x.style.color) = 'black';
return true;
}
}
}
Aucun commentaire:
Enregistrer un commentaire