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 a way to change the date format in jQuery Validation?
Asked
Active
Viewed 1.3k times
2 Answers
16
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);
}

Charly
- 861
- 7
- 10
-
Ohh man.. It work fine for me.. I wasted almost a day to fix this.. Thanks – shanmugharaj Apr 19 '15 at 11:44
-
This seems to fix the problem for me but it breaks/disconnects all other javascript. Maybe I'm using the code above incorrectly? I simply included it upon document ready. Many thanks – Ian Jan 06 '16 at 10:59
-
@Charly Thanks.Works for me finally – Bimal Das Mar 26 '17 at 08:43
4
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
.

Community
- 1
- 1

Darin Dimitrov
- 1,023,142
- 271
- 3,287
- 2,928