function countNumber(stringtoCount) { var numCount = 0; for (var i = 0; i < stringtoCount.length; i++) { var char = stringtoCount.charAt(i); if (char != " " && !isNaN(char)) { numCount ++; } } return numCount ; } document.write(countNumber("56ghlkj78"));