2012-11-02 100 views
0

對於日期比較,具有以下驗證,當輸入無效日期時起作用,即結束日期在開始日期之前。但問題是驗證也會在沒有日期輸入時進行。JQuery驗證條件日期比較

我只想在輸入開始日期和結束日期時使用驗證。

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

回答

0

也許首先使用條件函數?

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

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

} 
+0

這對你有幫助我接受了嗎? :) – VIDesignz