2012-04-24 67 views
13

您好我正在使用jQuery驗證插件。jquery驗證,當輸入字段有一個標題屬性,而不是錯誤消息標題給出的錯誤消息

我有一個奇怪的問題,我有這樣的

jQuery("#profile_info").validate({ 

    rules : { 
     city : { 
      required : true, 
      minlength : 3, 
      maxlength : 30, 
      cityvalidation: true 
     }, 
     state : { 
      required : true, 
      minlength : 3, 
      maxlength : 30, 
      cityvalidation: true 
     } 
    }, 
    messages : { 
     city : { 
      required : " City must be filled in", 
      minlength : "At least 3 characters long", 
      maxlength : "Should not exceed 30 characters", 
     }, 
     state : { 
      required : " State must be filled in", 
      minlength : "At least 3 characters long", 
      maxlength : "Should not exceed 30 characters", 
     } 
    } 
}); 

cityvalidation

jQuery.validator.addMethod("cityvalidation", function(value, element) { 
     return this.optional(element) || /^[a-zA-Z\u0080-\u024F\s\/\-\)\(\`\.\"\']+$/i.test(jQuery.trim(value)); 
    }, "You Have Typed Unallowed Charactors"); 

我輸入字段validaion是

            <div class="select-date-container-side location-codes"> 
                 <input id="city" name="city" 
                  value="<?php if(isset($profileinfo['CityName'])){echo $profileinfo['CityName'];}else if(isset($city)){echo $city;} ?>" 
                  title="City" type="text" 
                  class="smaler-textfield textfield clear-default" 
                  tabindex="1900" /> 
                </div> 
                <div class="select-date-container-middle location-codes"> 
                 <input id="state" name="state" 
                  value="<?php if(isset($profileinfo['StateName'])){echo $profileinfo['StateName'];}else if(isset($state)){echo $state;} ?>" 
                  title="State" type="text" 
                  class="smaler-textfield textfield clear-default" 
                  tabindex="1900" /> 
                </div> 

如果cityvalidation失敗。 "You Have Typed Unallowed Charactors"消息,但不是顯示字段的標題。

enter image description here

  • 如果我刪除它完美的稱號。所以我願意做。我想獲得自定義錯誤消息,而不是標題。請幫助........

在此先感謝.....................

回答

22

嗯,我發現它。

我用ignoreTitle: true,

jQuery("#profile_info").validate({ 


    ignoreTitle: true, 

    rules : { 
     city : { 
      required : true, 
      minlength : 3, 
      maxlength : 30, 
      cityvalidation: true 
     }, 
     state : { 
      required : true, 
      minlength : 3, 
      maxlength : 30, 
      cityvalidation: true 
     } 
    }, 
    messages : { 
     city : { 
      required : " City must be filled in", 
      minlength : "At least 3 characters long", 
      maxlength : "Should not exceed 30 characters", 
     }, 
     state : { 
      required : " State must be filled in", 
      minlength : "At least 3 characters long", 
      maxlength : "Should not exceed 30 characters", 
     } 
    } 
});