check if string contains numbers js code example
Example 1: js check if string is number
isNaN(num)
isNaN(123)
isNaN('123')
isNaN('1e10000')
isNaN('foo')
isNaN('10px')
Example 2: check if a string contains digits js
function hasNumber(myString) {
return /\d/.test(myString);
}
Example 3: js string have number js
var hasNumber = /\d/;
hasNumber.test("ABC33SDF");
hasNumber.test("ABCSDF");
Example 4: how to check if a string contains numbers in javascript
function hasNumbers(str){
var regexp = /d/g;
return regexp.test(str);
};
hasNumbers("I am 20years old");
hasNumbers("I am a boy");