PA6OTA
-1
Q:

js check if string is integer

var myString     =  "abc123";
var otherString  =  "123";
/* isInterger() checks if an value repersents an int  */

isInteger(myString);    //returns false
isInteger(otherString); //returns true
40
if (typeof myVar === 'string'){
    //I am indeed a string
}
13
Number.isInteger(value)

//returns a Boolean
7
isNaN(num)         // returns true if the variable does NOT contain a valid number

isNaN(123)         // false
isNaN('123')       // false
isNaN('1e10000')   // false (This translates to Infinity, which is a number)
isNaN('foo')       // true
isNaN('10px')      // true
4
function isInt(str) {
  return !isNaN(str) && Number.isInteger(parseFloat(str));
}
0
var myString     =  "abc123";
var otherString  =  "123";
/* isInterger() checks if an value repersents an int  */

Number.isInteger(myString);    //returns false
Number.isInteger(otherString); //returns true
0
isNaN(num)         // returns true if the variable does NOT contain a valid number
1

New to Communities?

Join the community