Wednesday, August 19, 2009

Custom date handling in jQuery validation

Last few days we are transfering our code from prototype to jQuery. I found jQuery
to be better than prototype, better documentation, plugins, and much easier.

I had a problem with date fields, that needed to be in format dd.mm.yyyy.
By default jQuery validation plugin works with dates yyyy/mm/dd.

To resolve this issue, and make it work with your format :


$.validator.addMethod(
"customDate",
function(value, element) {
return value.match(/^\d\d?\.\d\d?\.\d\d\d\d$/);
},
"Date error, format dd.mm.yyyy"
);

Later in you HTML code in date field put this :

No comments:

Post a Comment