Using regular expressions to validate a numeric range

后端 未结 11 1570
自闭症患者
自闭症患者 2020-11-21 22:16

My input number is an int. But the input number must be in a range from -2055 to 2055 and I want to check this by using regular expression.

So is there anyway to wri

11条回答
  •  借酒劲吻你
    2020-11-21 22:51

    Yet another -

     #  ^-?0*(?:20(?:[0-4][0-9]|5[0-5])|[0-9]{1,3})$
    
     ^ 
     -?
     0*
     (?:
          20
          (?:
               [0-4] [0-9] 
            |  
               5 [0-5] 
          )
       |  
          [0-9]{1,3} 
     )
     $
    

提交回复
热议问题