我想检查string
是否只包含数字。我使用了这个:
var isANumber = isNaN(theValue) === false;
if (isANumber){
..
}
但意识到它也允许+
和-
。基本上,我希望确保input
只包含数字,不包含其他字符。因为+100
和-5
都是数字,所以isNaN()
不是正确的方法。也许我需要一个正则表达式?有什么建议吗?
https://stackoverflow.com/questions/1779013
复制相似问题