Why doesn't [01-12] range work as expected?

后端 未结 6 1744
有刺的猬
有刺的猬 2020-11-22 03:34

I\'m trying to use the range pattern [01-12] in regex to match two digit mm, but this doesn\'t work as expected.

6条回答
  •  长情又很酷
    2020-11-22 04:26

    Use this:

    0?[1-9]|1[012]
    
    • 07: valid
    • 7: valid
    • 0: not match
    • 00 : not match
    • 13 : not match
    • 21 : not match

    To test a pattern as 07/2018 use this:

    /^(0?[1-9]|1[012])\/([2-9][0-9]{3})$/
    

    (Date range between 01/2000 to 12/9999 )

提交回复
热议问题