1// native returns true if the variable does NOT contain a valid number
2isNaN(num)
3
4// can be wrapped for making simple and readable
5function isNumeric(num){
6 return !isNaN(num)
7}
8
9isNumeric(123) // true
10isNumeric('123') // true
11isNumeric('1e10000') // true (This translates to Infinity, which is a number)
12isNumeric('foo') // false
13isNumeric('10px') // false
1function isNumber(n) { return /^-?[\d.]+(?:e-?\d+)?$/.test(n); }
2
3------------------------
4
5isNumber('123'); // true
6isNumber('123abc'); // false
7isNumber(5); // true
8isNumber('q345'); // false
9isNumber(null); // false
10isNumber(undefined); // false
11isNumber(false); // false
12isNumber(' '); // false
1var myString = "abc123";
2var otherString = "123";
3/* isInterger() checks if an value repersents an int */
4
5Number.isInteger(myString); //returns false
6Number.isInteger(otherString); //returns true