Regex for number check below a value

前端 未结 6 1429
-上瘾入骨i
-上瘾入骨i 2020-12-11 05:54

I\'m still a beginner at regex so this is a little above me currently.

I need to validate a number input to two characters and it can\'t be more than the value 12.

6条回答
  •  [愿得一人]
    2020-12-11 06:20

    For something like this (testing if an integer is less than a given value), you should really not use a regex.

    Instead, just use a simple condition like this one (the syntax will depend on the language you're working with) :

    if ($variable <= 12) {
      // OK
    }
    else {
      // Not OK
    }
    

提交回复
热议问题