A regular expression to match and validate a 4-digit year (from 1900 to 2099).
/^(19|20)[\d]{2,2}$/
Matches:
- 2020
- 1900
- 1980
If you’re looking for a regex to match years from 1000 to 2999, use this instead.
/^[12][0-9]{3}$/
Matches:
- 1024
- 2100
- 1980
See Also:
- Date (dd/mm/yyyy) Regular Expression
- 12-Hour Time (hh:mm:ss) Regular Expression
- 24-Hour Time (HH:mm:ss) Regular Expression
- Month Regular Expression
- Regular Expression To Match Names Of The Days Of The Week
- Regular Expression To Match Month Name
- Regex To Match A Valid Day In A Date String