-1

Used below code to regex filter.

(20[01]\d|20[01]\d)

But, it allows from 2000 to 2019. But, I need only from 2009 to 2019. Please let me know how to change this logic?

Also, next year.. if I want to change manually from 2010 to 2020. can you use the same regex by changing nos.?

Mukyuu
  • 6,436
  • 8
  • 40
  • 59
TDG
  • 1,294
  • 4
  • 18
  • 50
  • 4
    why use a regular expression? – epascarello Nov 14 '19 at 02:12
  • @epascarello A `pattern` attribute can make providing feedback to the user a bit easier, right? – CertainPerformance Nov 14 '19 at 02:14
  • 2
    @CertainPerformance And so could number with min and max. – epascarello Nov 14 '19 at 02:15
  • @CertainPerformance The feedback for a pattern is inscrutible. it just says you need to fit the pattern, it doesn't explain what the pattern is. And if it showed the pattern, how many users would understand this? – Barmar Nov 14 '19 at 02:18
  • 3
    [Regex Numeric Range Generator](http://gamon.webfactional.com/regexnumericrangegenerator/) says `(2009|201[0-9])` – Robert Harvey Nov 14 '19 at 02:18
  • Can you use Year value from the date object for comparison, looks like you are taking last 10 years as valid. So, year from current date and year from current date - 10 years, then check if the selected date is between this range – Prateek Kumar Dalbehera Nov 14 '19 at 02:19

2 Answers2

1

Because all permissible numbers start with 20, put that at the start of the pattern. Then you want to match 09 to 19 numerically - either match 09, or match 1 followed by another digit:

20(?:09|1\d)

https://regex101.com/r/h9BHXA/1

from 2010 to 2020

Same sort of thing. 1\d matches the digits in the tens, and alternate with 20:

20(?:1\d|20)
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
0

To capture the numbers between 2009 and 2019 you can use the following:

2009|201[0-9]

And for the interval between 2010 and 2020:

201[0-9]|2020

Reference: http://gamon.webfactional.com/regexnumericrangegenerator/

magamig
  • 414
  • 4
  • 14