Regular Expression Match to test for a valid year

后端 未结 14 1799
清歌不尽
清歌不尽 2020-11-29 02:27

Given a value I want to validate it to check if it is a valid year. My criteria is simple where the value should be an integer with 4 characters. I know this is

14条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 03:11

    /^\d{4}$/ This will check if a string consists of only 4 numbers. In this scenario, to input a year 989, you can give 0989 instead.

提交回复
热议问题