use maxlength and required of jquery

I found that maxlength and requeried of jquery cannot use together. so we need to add a new method to validate a special field which need length limitation and also a field which is requried. code is as below:

$(document).ready(function(){}); 写道
$.validator.addMethod("lengthValidate", function(value, element, param) {
//len($.trim())
var length = $.trim(value).length;

/*var length = len($.trim(value));*/
testPram = param;
return length <= param;
}, $.format("Please enter no more than {0} characters."));

$("#frmIIBApproveRequest").validate({
rules:{
txtDes:{lengthValidate : 250 },
txtABN:{ lengthValidate : 50 },
txtVenderID:{ lengthValidate : 15 },
txtIIBComments:{ required:true }
}
});
});
function iibApproveF(){
if($("#frmIIBApproveRequest").validate().element("#txtDes")
&&$("#frmIIBApproveRequest").validate().element("#txtIIBComments")&&confirm("Are you sure you want to approve the request?")){
$("#hidRequestSts").val('1');
$("#frmIIBApproveRequest").get(0).submit();
}
}
 

你可能感兴趣的:(jquery)