这是一个验证整数的解决方案。有人可以解释一下 Karim's answer 的逻辑吗? .
这非常有效,但我无法理解如何实现。
var intRegex = /^\d+$/;
if(intRegex.test(someNumber)) {
alert('I am an int');
...
}
最佳答案
正则表达式:/^\d+$/
^ // beginning of the string
\d // numeric char [0-9]
+ // 1 or more from the last
$ // ends of the string
当它们全部组合在一起时:
从字符串的开头到结尾有一个或多个数字char[0-9]和number only。
关于javascript - 在javascript中验证一个字符串是非负整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16941386/