Jquery Validate表單驗證,自定義校驗正整數


 1     // 添加自定義校驗規則,校驗正整數
 2     jQuery.validator.addMethod("positiveinteger", function(value, element) {  3         var Val = parseInt(value);  4         return Val > 0 && (Val + "") == value;  5     }, "請輸入正整數");  6 
 7     // 表單驗證
 8     $('#rebate_num_form').validate({  9         errorPlacement: function(error, element) { 10             $(element).next('.field_notice').hide(); 11  $(element).parent().append(error); 12  }, 13         success: function(label) { 14             label.addClass('right').text('OK!'); 15  }, 16         onkeyup: false, 17  rules: { 18  num: { 19                 required: true, 20                 number: true, 21                 positiveinteger: true
22  } 23  }, 24  messages: { 25  num: { 26                 required: '不能為空', 27                 number: '只能是數字', 28                 positiveinteger: '只能是正整數'
29  } 30  } 31     });


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM