RegExp range of number (1 to 36)

后端 未结 7 1480
臣服心动
臣服心动 2020-12-06 00:32

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 would like to test a number between 1

7条回答
  •  我在风中等你
    2020-12-06 00:53

    You know about \d, right?

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

    Try this in console:

    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("
    "); } }

提交回复
热议问题