javascript - Validate date with Moment.js according to culture format -


i must validate date according date format of culture.. example have need validate date either english culture ("mm/dd/yyyy") or italian culture ("dd/mm/yyyy").

for reason, date validate english culture. example want validate english format date:

moment.locale('en'); // <-- set culture  moment('12/13/2015').isvalid(); // <-- return true, ok moment('13/12/2015').isvalid(); // <-- return false, ok 

now want validate same date, changing culture:

moment.locale('it'); // <-- set culture  moment('12/13/2015').isvalid(); // <-- return true, should false moment('13/12/2015').isvalid(); // <-- return false, should true 

how have use moment.js validate date? thank you.

for validation known format can use:

moment('13/12/2015',['dd/mm/yyyy']).isvalid(); 

try way:

> moment.locale('it') 'it' > var m = moment('13/12/2015', 'l'); undefined > m.isvalid() true > m.format() '2015-12-13t00:00:00-05:00' 

Comments