What is the regex expression for validating year in the YYYY format?

Hi:

I've got pretty limited experience dealing with regex expressions.

I'm looking for a regex expression to validate the following: Valid Year in the form YYYY.
We want to check for years in the 1000's through to the 2000's.

I came up with something like this:
^(15|16|17|18|19|20)\d\d

Open in new window

This would work for years from 1500 - 2099
But I think there must be something a little cleaner/more elegant.

Thanks,
JohnB
LVL 1
jxbmaSoftware ConsultantAsked:
Who is Participating?
 
it_saigeDeveloperCommented:
For 1000 to 2999 it would be:
^[12][0-9]{3}$

Open in new window

-saige-
0
 
jxbmaSoftware ConsultantAuthor Commented:
Awesome.

JB
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.