check if string contains integer javascript code example

Example 1: check if a string contains digits js

function hasNumber(myString) {
  return /\d/.test(myString);
}

Example 2: js string have number js

var hasNumber = /\d/;   
      hasNumber.test("ABC33SDF");  //true
      hasNumber.test("ABCSDF");  //false

Example 3: js check if string is int

function isNumeric(str) {

	// Check if input is string
	if (typeof str != "string")
    	return false

	// Use type coercion to parse the _entirety_ of the string
    // (`parseFloat` alone does not do this).
	// Also ensure that the strings whitespaces fail
	return !isNaN(str) && 
		!isNaN(parseFloat(str)) 
}

Example 4: js check if string or int

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

Number.isInteger(myString);    //returns false
Number.isInteger(otherString); //returns true