Regular Expression For Year

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: