2013-06-18 47 views
0

我正在使用jquery驗證插件來驗證jquery中的時間...但它總是顯示一個錯誤,這真的讓我拉我的頭髮。我如何在我的項目中使用jQuery驗證插件

Uncaught TypeError: Cannot call method 'addMethod' of undefined

$("input").blur(function() { 
       //var check =$(this).closest('tr').find('input'); 
       $(this).each(function() { 
       $.validator.addMethod(this, function(value, element) { 
       return this.optional(element) || /^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?$/i.test(value); 
        }, "Please enter a valid time."); 

       $("#check").validate({ 
          rules: { 
          input: "required time" 
            } 

       }); 
+0

#檢查這裏是我的表格ID .. – Rozer

+0

第一,請在沒有擴展方法的情況下嘗試驗證器。例如,只需要一個基本的「必需」。如果這樣做,嘗試在添加方法之前啓動驗證程序。 – TCHdvlp

回答

0

你缺少在你的頁面的validator library,包括library在你的頁面

<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"></script> 

而且

$.validator.addMethod('timevalue', function(value, element) { 
    return this.optional(element) || /^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?$/i.test(value); 
}, "Please enter a valid time."); 


$("#check").validate({ 
    rules: { 
     timevalue: true 
    } 
}); 
+0

我已通過驗證程序庫,但顯示相同的錯誤.. @ Arun P Johny – Rozer

相關問題