Does anyone have any ideas on if/how one could create a regular expression to match a date in any given period?
Two examples:
23/11/2008 - 12/04/2010
//The expression would evaluate whether 16/04/2010 was in this range, and return false.
//The expression would determine whether 03/12/2009 was in this range, and return true.
and
01/09/1984 - 30/04/2001
//The expression would evaluate whether 16/04/1990 was in this range, and return true.
//The expression would determine whether 03/12/2009 was in this range, and return false.
I've been racking my brain on how to come up with something, but I've got nothing that comes close. Examples on the web are only interested in checking whether a date is in a particular format, but nothing about validating ranges.
The reason I tagged C# in this is because, this couldn't be done in straight regex, and the range regex would need to be built manually for each individual case.
Wouldn't it be easier to parse the strings to DateTime
s and comparing those?
I don't think you should regular expressions for range checks. First check whether the date is valid with a regular expression, then check whether it falls in the given period.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With