javascript - 在javascript中验证一个字符串是非负整数

标签 javascript regex validation integer

这是一个验证整数的解决方案。有人可以解释一下 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/

相关文章:

javascript - 为什么使用 new 调用函数时,在不使用 new 的情况下调用函数时不会返回相同的引用

javascript - 如何使用标签中的超链接自定义谷歌图表?

javascript - 简单的javascript字符串提取

Java Json String 提取数字并替换特定文本

ruby-on-rails - Rails before_validation 剥离空白最佳实践

javascript - 使用 window.location.href 或 .assign 或 .reload 时等待时间很长

JavaScript 在 Firefox 下可以工作,但在 IE 下不起作用

php - 命令行指令解析

javascript - 在 Scala Play 框架中使用 javascript 进行电子邮件验证?

javascript - 如何使用 javascript 或 jquery 限制字段中输入的字符数?