2012-01-09 118 views
2

我正在使用jQuery验证插件来验证我的表单,我如何验证此日期格式的自定义日期DD-MMM-YYY(23-Mar-2012)。jQuery验证插件:验证自定义日期格式

+0

使用jQuery验证插件[自定义日期格式可能重复在(http://stackoverflow.com/questions/511439/custom-date-format-with-jquery-validation-plugin) – 2013-11-24 06:41:43

回答

5

Create a custom validator

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"); 
3

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" 
); 

检查还引用后:Custom date format with jQuery validation plugin

另外:Validate two dates of this "dd-MMM-yyyy" format in javascript