I need a pattern that accepts mm/dd/yyyy and yyyy-mm-dd formats. I will put it inside Validators.pattern()
as parameter.
Inputs such as 10/20/2019 or 2019-10-20 are valid.
How do I solve this problem?
I need a pattern that accepts mm/dd/yyyy and yyyy-mm-dd formats. I will put it inside Validators.pattern()
as parameter.
Inputs such as 10/20/2019 or 2019-10-20 are valid.
How do I solve this problem?
This RegEx might help you to do so:
(([0-9]+)-([0-9]+)-([0-9]+))|(([0-9]+)\/([0-9]+)\/([0-9]+))
If you wish, you can add additional boundaries to it, such as this expression:
(([0-9]{4})-([0-9]{2})-([0-9]{2}))|(([0-9]{4})\/([0-9]{2})\/([0-9]{2}))
which has quantifier boundaries. Also, I have added capturing groups such that you can call any part of the date that you wish, together or separately.
You can reduce the boundaries also if it is not necessary.