Jquery验证条件日期比较

时间:2012-11-02 19:45:39

标签: jquery date jquery-validate

对日期比较进行以下验证,在输入无效日期时起作用,即结束日期在开始日期之前。但问题是,当没有输入日期时,验证也会启动。

如果输入了开始日期和结束日期,我只想使用验证。

 $j("#Form1").validate(
    {

        rules:
            {
                content_0$leftcolumn_0$whiteboxplaceholder_0$exportFilterFromActivityDate: {
                    date: true,
                    required: false
                },
                content_0$leftcolumn_0$whiteboxplaceholder_0$exportFilterToActivityDate: {
                    date: true,
                    required: false,
                    isAfterStartDate: "#content_0_leftcolumn_0_whiteboxplaceholder_0_exportFilterFromActivityDate"
                },
                content_0$leftcolumn_0$whiteboxplaceholder_0$exportFilterFromFinalApprovalDate: {
                    date: true,
                    required: false
                },
                content_0$leftcolumn_0$whiteboxplaceholder_0$exportFilterToFinalApprovalDate: {
                    date: true,
                    required: false,
                    isAfterStartDate: "#content_0_leftcolumn_0_whiteboxplaceholder_0_exportFilterFromFinalApprovalDate"
                }
            }
    });

1 个答案:

答案 0 :(得分:-1)

可能先使用条件函数吗?

if( ($('#dateA').val()!='') && ($('#dateB').val()!='') ){

    $j("#Form1").validate({Validate....});

}