jQuery-检查字符串是否包含数值 [英] jQuery - check whether string contains numeric value
问题描述
如何通过jquery检查字符串是否包含任何数值?
How to check whether a string contains any numeric value by jquery?
我搜索了许多示例,但只得到了检查数字的方法,而不是STRING中的数字.我正在尝试找到类似$(this).attr('id').contains("number");
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:我的DOM ID将类似于Large_a
(不具有数字值),Large_a_1
(具有数字值),Large_a_2
等)
(p/s: my DOM id will be something like Large_a
(without numeric value) , Large_a_1
(with numeric value), Large_a_2
, etc.)
我应该使用哪种方法?
推荐答案
此代码可检测到以下划线符号开头的结尾数字( azerty1_2 将匹配"2",但是 azerty1 不匹配):
This code detects trailing digits preceded by the underscore symbol (azerty1_2 would match "2", but azerty1 would not match):
if (matches = this.id.match(/_(\d)+$/))
{
alert(matches[1]);
}
这篇关于jQuery-检查字符串是否包含数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!