var digits = "0123456789";
// U.S. phone numbers have 10 digits.
// They are formatted as 123 456 7890 or (123) 456-7890.
var digitsInUSPhoneNumber = 10;
var phoneNumberDelimiters = "()- ";
var validUSPhoneChars = digits + phoneNumberDelimiters;
function stripCharsInBag (s, bag)
{
var returnString = "";
for (var i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
}
return returnString;
}
function validUSPhone(phoneNumber)
{
var normalizedPhone = stripCharsInBag(phoneNumber, phoneNumberDelimiters)
return (isInteger(normalizedPhone) && normalizedPhone.length == digitsInUSPhoneNumber)
}
function isInteger(s)
{
for (var i = 0; i < s.length; i++)
{
if (!isDigit(s.charAt(i))) return false;
}
return true;
}
function isDigit (c)
{ return ((c >= "0") && (c <= "9"))
}
function validFax(faxNumber)
{ return validUSPhone(faxNumber);
}