JavaScript 正则表达式 5-5000

标签 javascript regex

我知道这个:

var regStartMoney = /[1-5][0-9][0-9][0-9]/;

允许您输入 1-5999 之间的数字。

如何在 5-5000 范围内进行计算?

最佳答案

正则表达式滥用!只要以理智的方式去做就可以了:

var int = parseInt(input,10);
if (isNan(input)) {
    alert('Please enter a number.');
} else if (input != int) {
    alert('Decimals are not allowed.');
} else if (!(int >= 5 && int <= 5000)) {
    alert('Your number must be between 5 and 5000 (inclusive).');
} else {
    alert('Your number is valid!');
}

关于JavaScript 正则表达式 5-5000,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22521543/

相关文章:

javascript - AJAX 到 PHP 到 mySQL 调试

javascript - 如何将本地 html 文件显示到 webview 中?

Javascript 无法点击

.net - 匹配不以 [ 且不以 ] 结尾的行的正则表达式(ini header )

regex - 从结构松散的文本中解析价格

regex - 仅匹配以字符开头的

javascript - Reactjs/Javascript 更新对象键名

javascript - 如何在 HTML/Javascript 中创建递归菜单?

python - 如何编写一个 python 正则表达式否定环视,其中两个断言都必须为真?

regex - 如何使用 RegExp 从文本中删除除 ä、ö 和 ü 之外的所有非单词字符