Clientside validation fails for date format dd/mm/yyyy in jQuery Validate

ぃ、小莉子 提交于 2019-11-30 10:11:39

Adding to Darin's answer. If you happen to already be using the datepicker plugin from JQuery UI then you can use that date parser instead of creating your own:

$.validator.methods.date = function (value, element) {
    return this.optional(element) ||  $.datepicker.parseDate('dd/mm/yy', value);
}
Darin Dimitrov

You could override the date parsing method of the validate plugin:

$.validator.methods.date = function (value, element) {
    return this.optional(element) || parseDate(value, "yyyy-MM-dd") !== null;
}

Here parseDate is a function that you could write yourself. The following thread might give you some ideas. Or use some existing plugin such as datejs or Globalize.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!