How to validate a date?

前端 未结 12 1656
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 04:13

I\'m trying to test to make sure a date is valid in the sense that if someone enters 2/30/2011 then it should be wrong.

How can I do this with any date?

12条回答
  •  别跟我提以往
    2020-11-22 04:39

    I recommend to use moment.js. Only providing date to moment will validate it, no need to pass the dateFormat.

    var date = moment("2016-10-19");
    

    And then date.isValid() gives desired result.

    Se post HERE

提交回复
热议问题