【问题标题】:jQuery validation plugin: validate custom date formatjQuery 验证插件:验证自定义日期格式
【发布时间】:2012-01-09 20:35:14
【问题描述】:

我正在使用 jQuery Validate 插件来验证我的表单,我如何使用这种日期格式 DD-MMM-YYY(2012 年 3 月 23 日)验证自定义日期。

【问题讨论】:

标签: javascript jquery date validation


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    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

    【讨论】:

      猜你喜欢
      • 2010-10-05
      • 2018-10-21
      • 2012-10-11
      • 1970-01-01
      • 1970-01-01
      • 2012-07-22
      • 1970-01-01
      • 2011-12-24
      相关资源
      最近更新 更多