RegExp数量范围(1到36) [英] RegExp range of number (1 to 36)

查看:128
本文介绍了RegExp数量范围(1到36)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了很多,找不到这个RegExp的解决方案(我不得不说我在Reg。表达方面不是很有经验)。

I searched a lot and can't find the solution for this RegExp (I have to say I'm not very experienced in Reg. Expressions).

I想测试一个介于1到36之间的数字,不包括0和37及以上。

I would like to test a number between 1 and 36, excluding 0 and 37 and above.

到目前为止我已经得到了什么,几乎可以工作(它不接受17 ,18,19,27,28,29)...

What I've got so far and almost works (it doesn't accept 17, 18, 19, 27, 28, 29)...

^[1-9]{1}$|^[1-3]{1}[0-6]{1}$|^36$;

有人可以帮我吗?

推荐答案

你知道 \d ,对吧?

^([1-9]|[12]\d|3[0-6])$

在控制台中尝试:

function test() {
    for(var i = 0; i < 100; i++) {
        if (/^([1-9]|[12]\d|3[0-6])$/.test(i.toString()) != (i >= 1 && i <=36)) {
            document.write(i + "fail");
        }
                else
                document.write(i + "pass");
        document.write("<br/>");
    }
}

这篇关于RegExp数量范围(1到36)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆