1

I want to do something similar to what was required in this post: Regex Valid Year check

I would like to do something similar but only with years between 2011 & 2099?

Thanks, Mac

mcquaim
  • 159
  • 7
  • 15

3 Answers3

8

My taste would be for parsing as an integer (Integer.parseInt()) and checking the bounds with <= or similar. But if you insist on the regular expression:

^20(1[1-9]|[2-9][0-9])$

The first case covers 2011–2019, the other 2020–2099. I have not tested.

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
1

Here is an example

^20((1[1-9])|([2-9][0-9]))$

it matches exactly from 2011 to 2099

Simo
  • 195
  • 1
  • 16
0

Try this:

^20[1-9][0-9]$

^20 starts with 20 [1-9] followed by 1,2,3,4,5,6,7,8,9 [0-9] followed by 0,1,2,3,4,5,6,7,8,9

Edit: It will also accept 2010.

See this Answer by Ole V.V.