Regex for numeric range from negative numbers?

前端 未结 6 1980
忘掉有多难
忘掉有多难 2021-02-13 19:34

I want to validate a number using regex.. the condition is number can be from any negative 3 digit values to positive 3 digit.. but cannot be zero.

can someone please he

6条回答
  •  长发绾君心
    2021-02-13 20:21

    Assuming you are dealing with whole integers, and your number don't mix with other texts, you can try this

    ^-?[1-9][0-9]{0,2}$
    

    I agree with Anon, it is much better to read the String, and convert it to int to do the comparison, if you have predictable inputs.

提交回复
热议问题