Regex for numeric range from negative numbers?

前端 未结 6 2052
忘掉有多难
忘掉有多难 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:16

    I have some experiments about regex in django url, which required from negative to positive numbers

    ^(?P(\-\d+|\d+))$
    

    Let's we focused on this (\-\d+|\d+) part and ignoring others, this semicolon | means OR in regex, then if we got negative value it will be matched with this \-\d+ part, and positive value into this \d+ part

提交回复
热议问题