0

I made a google forms which i asked a date of birth like dd/mm/yyyy. I'm looking for a RegEx that allow every date from 01/01/1900 to 31/12/2015 but refuse every date who contains this 5 years 2016, 2017, 2018, 2019, 2020. Does someone have an idea ? Thanks for help.

  • Quick! Is `02/30/1900` a valid date? – Cary Swoveland May 23 '20 at 03:17
  • The best way is to split on `/` and test each part numericaly. If you really want a regex, have a look at [this](https://stackoverflow.com/questions/5978510/regex-to-match-date/5978549#5978549) – Toto May 23 '20 at 09:16

1 Answers1

0

If you really only want to check dates for years 1900-2015, it suffices to code \b(\d{1,2}/\d{1,2}/(19\d{2}|200\d|201[0-5]))\b The \b...\b bound is less restrictive than ^...$ Because the previous answer did not specify any year bounds, they need to be added, for example, 1900…2099 (excluding 2016-2020) \b(?!2016|2017|2018|2019|2020)(\d{1,2}/\d{1,2}/(19|20)\d{2})\b

TonyR
  • 128
  • 1
  • 6
  • This "simple" regex does not check the validity of the day/month. Although this is certainly possible with regex, it can become fairly complex when leap years are also considered. – TonyR May 23 '20 at 06:31
  • The last regex is matching `01/01/2017`, https://regex101.com/r/MJWyPg/1 – Toto May 23 '20 at 09:11