How to check whether a string contains any numeric value by jquery?
I search through many examples but I only get the way to check for a number, NOT number in a STRING. I am trying to find something like $(this).attr('id').contains("number");
(p/s: my DOM id will be something like Large_a
(without numeric value) , Large_a_1
(with numeric value), Large_a_2
, etc.)
What method should I use?
You could use a regular expression:
var matches = this.id.match(/\d+/g);
if (matches != null) {
// the id attribute contains a digit
var number = matches[0];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With