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

前端 未结 2 1536
眼角桃花
眼角桃花 2021-01-01 05:10

I am using jQuery Validate plugin for clientside validation in an MVC 5 application. For the date fields cilentside validations fails when using dd/mm/yyyy format. Is there

2条回答
  •  长发绾君心
    2021-01-01 05:32

    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.

提交回复
热议问题