I have this string :
testString = "child 4 to 10 years old";
How to check if the string contains two (or more) numbers?
testString.match("??")
Thanks!
I have this string :
testString = "child 4 to 10 years old";
How to check if the string contains two (or more) numbers?
testString.match("??")
Thanks!
This would find a match if the string contains atleast two numbers.
testString.match(/(?:.*?\b\d+\b){2}/)
or
/(?:.*?\b\d+\b){2}/.test(str);
or
If you also want to deal with decimal numbers then try this,
/(?:.*?\b\d+(?:\.\d+)?\b){2}/.test(str);
if (testString.match(/(\d+)/).length >= 2) {
Is a very simple/readable solution.