In momentjs
is there a way to accept a wildcard while strictly parsing an input?
Strictly parse input by passing true
as the third parameter.
I'd like to accomodate DD/MM/YYYY
DD-MM-YYYY
DD.MM.YYYY
DD MM YYYY
.
I can add them all in an array, but I'd prefer to use *
or .
so I don't have to maintain the list. Is it possible to strictly require date format while ignoring delimiter?
moment('12/12/2012', ["DD/MM/YYYY", "DD-MM-YYYY", "DD.MM.YYYY", "DD MM YYYY"], true).isValid() === true;
// ideally ignore delimiter type, this evaluates to false
moment('12/12/2012', "DD*MM*YYYY", true).isValid() === false;
Strict parsing is logically the opposite of wildcard. As an example, you probably want to reject '01/01-2020'
.
That's specifically what the variant you're using is for (strict multi-format).
For non-strict cases the documentation is fairly clear:
The parser ignores non-alphanumeric characters, so both of the following will return the same thing.
moment("12-25-1995", "MM-DD-YYYY");
moment("12/25/1995", "MM-DD-YYYY");
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