Regular Expression For Year

Category: Date & Time

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:

Rate This Regex
Sending
User Review
0 (0 votes)

Expression Flags

Flags Description
i Ignore case sensitive.
g Allows global search.
m Allows multiline search.