I am using jQuery Validate plugin to validate my form, how can i validate a custom date with this date format DD-MMM-YYY (23-Mar-2012).
Asked
Active
Viewed 9,972 times
2
-
possible duplicate of [Custom date format with jQuery validation plugin](http://stackoverflow.com/questions/511439/custom-date-format-with-jquery-validation-plugin) – Ярослав Рахматуллин Nov 24 '13 at 06:41
2 Answers
5
jQuery.validator.addMethod("mydate", function(value, element) {
return this.optional(element) || /^\d\d?-\w\w\w-\d\d\d\d/.test(value);
}, "Please specify the date in DD-MMM-YYYY format");

Blazemonger
- 90,923
- 26
- 142
- 180
3
Look at http://www.intelligrape.com/blog/2010/03/31/client-side-date-validation-using-jquery-plugins/
jQuery.validator.addMethod("customDateValidator", function(value, element) {
// parseDate throws exception if the value is invalid
try{jQuery.datepicker.parseDate( 'm/dd/yy', value);return true;}
catch(e){return false;}
},
"Please enter a valid date"
);
Check also referenced post: Custom date format with jQuery validation plugin
Also: Validate two dates of this "dd-MMM-yyyy" format in javascript