我想验证该字段,以便不能超过今天的日期。我尝试过这样但我不知道如何调用此函数来验证日期:
jQuery.validator.addMethod( "greaterThan", function( value, element ) {
var now=new Date();
if ( !/Invalid|NaN/.test(new Date(value)) ) {
return new Date(value) > now;
}
return isNaN(value) || (parseFloat(value) > now);
},
'should not be greater than {0}.' );
答案 0 :(得分:0)
您可以通过执行以下操作来创建简单规则:
jQuery.validator.addMethod("greaterThanToday", function(value, element) {
var now=new Date();
if ( !/Invalid|NaN/.test(new Date(value)) ) {
return new Date(value) > now;
}
return isNaN(value) || (parseFloat(value) > now);
}, "* The date should not be greater than today.");
然后像这样应用:
$('#your_form').validate({
rules : {
your_date_field_name : { greaterThanToday : true }
}
});