How can I determine whether a given string represents a date?

后端 未结 11 1636
一个人的身影
一个人的身影 2020-12-11 00:31

Is there an isDate function in jQuery?

It should return true if the input is a date, and false otherwise.

11条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-11 01:20

    You should use moment.js it's the best lib to handle all kind of dates. Solution to your problem:

    var inputVal = '2012-05-25';
    moment(inputVal , 'YYYY-MM-DD', true).isValid();
    

提交回复
热议问题