Search code examples
momentjshandsontablepikaday

Custom format (or regex) with moment.js


It is possible to define some custom format containing a string to be ignored by moment.js ?

I have a date string like the following:

14-Apr [not valid]

I do not have the possibility of changing the date before passing it through moment.js and I'm wondering if moment.js would provide a way to deal with cases like this one.

Moment.js is being used by pikaday.js library which at the same time is being used by handsontable.js library.

pikaday.js doesn't have a callback such as onBeforeOpen and handsontable.js doesn't provide it either.


Solution

  • As stated in the docs "Moment's parser is very forgiving" so:

    moment("14-Apr random text", "DD-MMM");
    

    will be interpreted as a valid date (2016-04-14).