Here's how it should work. It parses the string until it reaches a numeric character.
You may be interested in checking the isFinite() function; it checks if the string is a final, legal number:
isFinite("123"); // true isFinite("123a");// false
However, this will return true for empty lines and spaces. Therefore, you can improve this solution by writing
mystring = "123"; mystringb = " "; !isNaN(parseInt(mystring)) && isFinite(mystring); // true !isNaN(parseInt(mystringb)) && isFinite(mystringb); // false
Based on these suggestions, I'm sure that you can create your own function that will ignore any string containing odd characters.
source share