How can I validate the range 1-99 using a regex?

后端 未结 11 1272
忘掉有多难
忘掉有多难 2021-02-07 03:00

I need to validate some user input, to ensure a number entered is in the range of 1-99 inclusive. These must be whole (Integer) values

Preceeding 0 is permitted, but opt

11条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-07 03:41

    Here you go:

    ^(\d?[1-9]|[1-9]0)$
    

    Meaning that you allow either of

    1. 1 to 9 or 01 to 09, 11 to 19, 21 to 29, ..., 91 to 99
    2. 10, 20, ..., 90

提交回复
热议问题