
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {           
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    //strips out spaces + - (). leaves letters and numbers, and all other chars
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone)
{
    s = stripCharsInBag (strPhone, validWorldPhoneChars);
    if (isInteger(s) && s.length >= minDigitsInIPhoneNumber)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function textBoxIsPhone(sID)
{
	var Phone = document.getElementById(sID).value;
	Phone = Phone.replace(/^\s+|\s+$/g,"");  // trims off start and end spaces
	if ((Phone==null)||(Phone==""))
    {
        return false;
	}
	if (checkInternationalPhone(Phone)==false)
    {
        return false;
	}
    return true;
 }



