Is MomentJS designed to parse user input?
I'm moderately close to simple cases where it takes dates in the DDMMYYYY order and handles some options.
It does not handle invalid dates especially well when specifying a format — including too high day values or year values for switching between 2 and 4 digits.
Examples of annual interpretation:
var date1 = moment('30082012', 'DDMMYYYY');
var date2 = moment('30082012', 'DDMMYY');
var date3 = moment('300812', 'DDMMYYYY');
var date4 = moment('300812', 'DDMMYY');
Examples of invalid dates:
var date5 = moment('08302012', 'DDMMYYYY');
var date6 = moment('08302012', 'DDMMYY');
var date7 = moment('083012', 'DDMMYYYY');
var date8 = moment('083012', 'DDMMYY');
I created JS Fiddle with these examples: http://jsfiddle.net/cHRfg/2/
Is there a way for a moment to accept a wider array of user input and reject invalid dates? Or is the library not designed for this?
source
share