检查字符是否是数字? [英] Check if character is number?
本文介绍了检查字符是否是数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要检查 justPrices [i] .substr(commapos + 2,1)
。
字符串类似于:blabla,120
The string is something like: "blabla,120"
在这种情况下,它会检查0是否为数字。怎么办呢?
In this case it would check whether '0' is a number. How can this be done?
推荐答案
你可以用 isNaN()
检查它是否不一个数字:
You can use isNaN()
to check if it is not a number:
var c = justPrices[i].substr(commapos + 2, 1);
if (!isNaN(parseInt(c, 10))) {
// Is a number
}
或者更详细:
if ('0123456789'.indexOf(c) !== -1) {
// Is a number
}
如果您不关心Internet Explorer:
And if you don't care about Internet Explorer:
if ('0123456789'.includes(c)) {
// Is a number
}
这篇关于检查字符是否是数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文