JQuery validate 日期比较

1.

$(function(){

jQuery.validator.methods.compareDate=function(value,element,param){

//varstartDate=jQuery(param).val()+":00";补全yyyy-MM-ddHH:mm:ss格式

//value=value+":00";

varstartDate=jQuery(param).val();

vardate1=newDate(Date.parse(startDate.replace("-","/")));

vardate2=newDate(Date.parse(value.replace("-","/")));

returndate1<date2;

};

jQuery("#__edit-form").validate({

focusInvalid:false,

rules:{

"orgCreateDate":{

required:false

},

"orgCancelDate":{

required:false,

compareDate:"#orgCreateDate"

}

},

messages:{

"orgCreateDate":{

required:"成立日不能为空!"

},

"orgCancelDate":{

required:"注销日期不能为空!",

compareDate:"注销日期必须大于成立日期!"

}

}

});*/

});

2.$(function(){

$.validator.addMethod(

"compareDate",

function(value,element){

varstartDate=$('#orgCreateDate').val();

returnnewDate(Date.parse(startDate.replace("-","/")))<=newDate(Date.parse(value.replace("-","/")));

},

"结束日期必须大于开始日期"

);

});

调用:

<inputtype="text"id="orgCancelDate"name="orgCancelDate"size="10"readonly="true"validate="{required:false,compareDate:true,maxlength:12}"value="<fmt:formatDatevalue="${org.orgCancelDate}"pattern="yyyy/MM/dd"/>"/>

相关推荐