jQuery validation plugin: validate custom date format

前端 未结 2 1960
醉梦人生
醉梦人生 2021-01-22 07:04

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).

2条回答
  •  臣服心动
    2021-01-22 07:44

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

提交回复
热议问题