mardi 14 avril 2015

How would I use the Javascript string.replace method to remove extra characters from a phone number? [duplicate]


This question already has an answer here:




I mean characters like periods, hyphens, spaces, or parentheses. I basically want it to see things like for example 2221112222 (222)1112222 , 222 1112222 , 222-111-2222 as the same. I have already coded what I have so far into a fiddle but I am unsure of where I went wrong with the isNaN



//should be numerical and able to strip out hyphens,parentheses,spaces, or periods
if (txtPhone.value == "" || isNaN(txtPhone.value) || txtPhone.value.length != 10) {
isValid = "false";
txtFeedback.innerHTML += "<p>Phone number should be numeric and 10-digits in length.</p>";
txtPhone.nextElementSibling.innerHTML = "Phone number should be numeric and 10-digits in length."
}

Aucun commentaire:

Enregistrer un commentaire