javascript ceck if number code example
Example 1: javascript check if number
function isNumber(n) { return /^-?[\d.]+(?:e-?\d+)?$/.test(n); }
------------------------
isNumber('123'); // true
isNumber('123abc'); // false
isNumber(5); // true
isNumber('q345'); // false
isNumber(null); // false
isNumber(undefined); // false
isNumber(false); // false
isNumber(' '); // false
Example 2: how to check if a string is an integer javascript
isNaN(num) // returns true if the variable does NOT contain a valid number