javascript regex validate years in range

后端 未结 8 1373
猫巷女王i
猫巷女王i 2021-02-13 20:11

I have input field for year and I need a regex for validation it. I have such code: ^([12]\\d)?(\\d\\d)$. But I want allow to validate only years in certain range (

8条回答
  •  遥遥无期
    2021-02-13 20:31

    For a range from 1950 to 2050 you may use the following regex:

    ^19[5-9]\d|20[0-4]\d|2050$
    

    Online demo

提交回复
热议问题