check value are not a number javascript code example
Example 1: check if input is a number javascript
// Another option is typeof which return a string
if (typeof(val) === 'number') {
// Guess what, it's a bloody number!
}
Example 2: 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 3: javascript check if is nan
function isNaN(x) {
return x !== x;
};
isNaN(NaN);//true