Regex for numeric range from negative numbers?

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

    There it´s It can or not start with the negative symbol, followed by a number between 1 and 9 ant then can be 0 to 2 of any number.

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

    Update: And the following regex also allows decimals

    ^\-?[1-9]\d{0,2}(\.\d*)?$
    

提交回复
热议问题