how to validate date in react

Solutions on MaxInterview for how to validate date in react by the best coders in the world

showing results for - "how to validate date in react"
Milla
13 Feb 2017
1const date = '2016-10-19';
2const dateFormat = 'DD-MM-YYYY';
3const toDateFormat = moment(new Date(date)).format(dateFormat);
4moment(toDateFormat, dateFormat, true).isValid();
5
6// Note: `new Date()` circumvents the warning that
7// Moment throws (https://momentjs.com/guides/#/warnings/js-date/),
8// but may not be optimal.
Raphaël
14 Jan 2020
1// using momentJS
2moment('Decimal128', 'YYYY-MM-DD').isValid() // true