Using regular expressions to validate a numeric range

后端 未结 11 1603
自闭症患者
自闭症患者 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:37

    Check out this great tool which generates a regex for numeric ranges:

    http://gamon.webfactional.com/regexnumericrangegenerator/

    For the range requested by OP it generates: -?([0-9]{1,3}|1[0-9]{3}|20[0-4][0-9]|205[0-5])

提交回复
热议问题