2012-07-10 81 views
0

我使用jquery.bassistance驗證插件。在我的領域驗證。現在我想在我的抵達文本框中進行驗證。我希望他在這個盒子上驗證。您在此複選框中使用的唯一字符是數字和:。驗證數字與jquery.bassistance驗證

我該如何做到這一點。我現在用這個代碼:

$(".validate").validate({ 
     rules: { 
      email: { 
       required: true, 
       email: true 
      }, 
      number: { 
       required:true, 
       minlength:3, 
       phoneAus:true 
      }, 
      math: { 
       equal: 11 
      }, 
      agree: "required" 
     }, 
     messages: { 
      email: "Vul een geldig email adres in", 
      agree: "Je moet nog akkoord gaan met voorwaarden" 
     }, 
     errorLabelContainer: $("form .error-messages") 
    }); 

但是數字驗證。在數字上進行驗證。我如何解決數字驗證問題。接受:標誌。

感謝

+0

你能告訴我們的HTML表單!? – 2012-07-10 09:51:49

回答

1

嘗試添加自定義的正則表達式規則,這裏是一個起點,你需要將正則表達式更新到您的具體要求:

$(function() 
{ 
    $.validator.addMethod("customRegex", function(value, element) { 
     return this.optional(element) || /^[0-9\:]+$/i.test(value); 
    }, "must contain only numbers, or a colon."); 

    $(".validate").validate({ 
     rules: { 
      "fieldId": { 
       required: true, 
       customRegex: true, 
      } 
     }, 
     messages: { 
      "fieldId": { 
       required: "You must enter a xyz", 
       customRegex: "format not valid" 
      } 
     } 
    }); 
});