简体   繁体   中英

Regular Expression for minimum value 18 and maximum 99 with leading zero

Regular Expression for minimum value 18 and maximum 99 with leading zero. Means my number should be from 18 to 99. With one condition of leading zero ie 18 == 018, 99 == 099

^0?1[89]|0?[2-9][0-9]$

  • ^ - beginning of string
  • 0? - allow beginning 0
  • 1[89] - match first character 1 and second 8 or 9
  • | - or
  • 0? - allow beginning 0
  • [2-9] - match first character 2-9
  • [0-9] - match second character 0-9
  • $ - end of string

Try this it will help you

Less than 18 and greater than 99 is not allowed

^(1[89]|[2-9][0-9])$

Try this:-

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

Demo: https://regex101.com/r/CrcbHN/1

(01[89])|(0[2-9]\\d)

  • (01[89]) matches 018 to 019
  • (0[2-9]\\d) matches 020 to 099

Try with below,

0([1][89]|[2-9][0-9])

DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM