最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Regular Expression for minimum value 18 and maximum 99 with leading zero - Stack Overflow

programmeradmin2浏览0评论

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 i.e 18 == 018, 99 == 099

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 i.e 18 == 018, 99 == 099

Share Improve this question edited May 13, 2017 at 6:30 Himanshu Shekhar asked May 13, 2017 at 6:21 Himanshu ShekharHimanshu Shekhar 1,2621 gold badge17 silver badges41 bronze badges 6
  • 2 what is your expectation from stackoverflow? – brk Commented May 13, 2017 at 6:24
  • 1 if (v> 17 && v < 100) ? – Mykola Borysyuk Commented May 13, 2017 at 6:24
  • I need regular expression for the above question. – Himanshu Shekhar Commented May 13, 2017 at 6:26
  • 1 If your allowable values are 18-99, how does a leading zero fit in to this? – AndrewR Commented May 13, 2017 at 6:27
  • @Mykola Borysyuk I want this (v> 17 && v < 100) condition in regex. – Himanshu Shekhar Commented May 13, 2017 at 6:28
 |  Show 1 more ment

5 Answers 5

Reset to default 6

Try this it will help you

Less than 18 and greater than 99 is not allowed

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

^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:-

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

Demo: https://regex101./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

发布评论

评论列表(0)

  1. 暂无评论