Forum Moderators: open
But as you've discovered, parseInt() simply ignores any trailing non-numbers, including spaces. The function parses however many numeric characters may occur at the start of a string, and returns NAN if the string doesn't begin with a number.
What you need to do is cycle through EACH character your "stripped" variable, testing for isNaN().
Example:
function checkPhoneNumber(stringEntered) {
stringEntered = stringEntered.replace(/[^0-9]/g, '');
if ((stringEntered.length == 7) ¦¦
(stringEntered.length == 10)) {
return true;
}
else {
return false;
}
} So...
checkPhoneNumber("888-888-8888");
...and...
checkPhoneNumber("888-8888");
will return true, but...
checkPhoneNumber("8a8-8ss-8a88");
...will return false.
Jordan