check if value is number js code example
Example 1: javascript check if number
if (Number.isInteger(val)) {
}
if (isNaN(val)) {
}
if (typeof(val) === 'number') {
}
Example 2: javascript check if number
if (Number.isInteger(val)) {
}
if (isNaN(val)) {
}
if (typeof(val) === 'number') {
}
Example 3: integer check in javascript
var a=Number.isInteger(5);
var b= Number.isInteger(01);
var c=Number.isInteger("10");
console.log(a,b,c);
Example 4: check if input is a number javascript
if (typeof(val) === 'number') {
}
Example 5: javascript is variable a string
if (typeof myVar === 'string'){
}
Example 6: javascript check if number
function isNumber(n) { return /^-?[\d.]+(?:e-?\d+)?$/.test(n); }
------------------------
isNumber('123');
isNumber('123abc');
isNumber(5);
isNumber('q345');
isNumber(null);
isNumber(undefined);
isNumber(false);
isNumber(' ');