Using regular expressions to validate a numeric range

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

    Why use Regex only to check a number?

    int n = -2000;
    
    if(n >= -2055 && n <= 2055)
    //Do something
    else
    //Do something else
    

提交回复
热议问题