How can I use javascript to check and see if a string has more than 1 integer?
ie.
var x = 1,15,30 { returns true }
var x = 13 { returns false }
How can I use javascript to check and see if a string has more than 1 integer?
ie.
var x = 1,15,30 { returns true }
var x = 13 { returns false }
Assuming that all items are integers:
function(s){ return s.indexOf(',')!=-1 }
Use regex to search for groups of digits (\d+
). If the length of all found groups is greater then 1 return true, if not return false.
function moreThenOneNumber(str) {
return str.match(/\d+/g).length > 1;
}
var x = '1,15,30';
var y = '13';
console.log(moreThenOneNumber(x));
console.log(moreThenOneNumber(y));