Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 184
  • Last Modified:

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
0
jxbma
Asked:
jxbma
1 Solution
 
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.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now