I want to validate my date field in "mm-dd-yyyy" format using jquery validation plugin. I want to display message "Please enter date in mm-dd-yyyy" if anybody vilates the date formar H开发者_StackOverflow社区ow will i do that ?
Thanks
the dateISO validation method should do what you need.
in your js, after including validator
jQuery.validator.addMethod("datetime", function(value, element) {
return this.optional(element) || /^\d{4}-\d{1,2}-\d{1,2}( \d{1,2}:\d{1,2}:\d{1,2})?$/.test(value);
}, "Please enter a valid date (YYYY-MM-DD)"
);
// connect it to a css class
jQuery.validator.addClassRules({
datetime : { datetime : true }
});
in your html
<input type='text' class='datetime' />
this actually allows to enter a datetime format for mysql (YYYY-MM-DD HH:MM:SS), but whatever.
$2c, *-pike
精彩评论