Date Regex with special character as optional pre element
I need a date regex for YYYY-MM-DD, plus the following four case:
1978-12-20
>1978-12-20
>=1978-12-20
<1978-12-20
<=1978-12-20
How can I allow those 5 scenarios?
Date Regex with special character as optional pre element
I need a date regex for YYYY-MM-DD, plus the following four case:
1978-12-20
>1978-12-20
>=1978-12-20
<1978-12-20
<=1978-12-20
How can I allow those 5 scenarios?
Imho, a regex is not the best tool for you, but if you still want to use a regex... a basic one, then you can use a regex like this:
^(?:>=?|<=?)?\d{4}-\d{2}-\d{2}$
Regex to match dates are kinda ugly. You can validate easily patterns, but dates have logic... for instance, not all months have 30 days, years are only 12 (should you count 01, 02, 03 or 1, 2, 3...).
Bear in mind that using above regex you will have invalid dates. So, you might want to capture the date string to ensure that it is valid first, and then apply this pattern to check if it is correct.