jquery validate 自定义验证小数前面9位,小数后面2位的js
jQuery.validator.addMethod("maxNumber",function(value, element){
var returnVal = true;
inputZ=value;
var ArrMen= inputZ.split(".");
if(ArrMen.length==2){
if(ArrMen[1].length>2){
returnVal = false;
return false;
}
}
var vzNum=parseFloat(inputZ).toFixed(2);
// alert(vzNum);
if(isNaN(vzNum)){
returnVal = false;
return false;
}
var ele= parseFloat('999999999.99');
if(ele<parseFloat(vzNum)){
returnVal = false;
return false;
}
// } for end
return returnVal;
},"请填写前面9位数字,小数为2位的金额");
<input class="required number maxNumber" id="paidFee_x${worksIndex.index}" name="carChauffeurOnceFeeDetail[${worksIndex.index}].paidFee" value="${chauffeurOnceFeeDetail.paidFee}" style="width:100px;" onBlur="accountingPrice(this)" <c:if test="${chauffeurOnceFeeDetail.status==1}">readonly="readonly"</c:if>/>
这个不重要 贴下.....
$(document).ready(function() {
//$("#name").focus();
$("#inputFormx").validate({
submitHandler: function(form){
// $("#myAlert").alert();
var elements =$(".qlMustM");
var isSub="true";
elements.each(function()
{
var $this = $(this);
//就收
//var ysje=$(this).parent("td").prev().prev().find("span").html();
//alert(ysje);
//应收
var ysje=$(this).parent("td").prev().prev().find("input");
//console.log(ysje);
//alert(ysje.val());
var fysje=parseFloat(ysje.val());
//alert(fysje);
//alert(fysje>0)
//如果应收为0 就不验证
if(fysje>0)
{
var spanV=$this.html();
// alert(spanV);
if(spanV==""||spanV==null){
$("#myAlert").css("display","block");
// $("#myAlert").show();
$("#myAlert").alert();
isSub="false";
return ;
}
if($this.html()>0){
$("#myAlert").css("display","block");
$("#myAlert").alert();
isSub="false";
return ;
}
}
});
if(isSub=="true"){
$("#myAlert").css("display","none");
}else{
return;
}
loading('正在提交,请稍等...');
//alert("xxxxxx");
form.submit();
},
rules: {
maxNumber: '999999999.99'
},
errorContainer: "#messageBox",
errorPlacement: function(error, element) {
$("#messageBox").text("输入有误,请先更正。");
if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
error.appendTo(element.parent().parent());
} else {
error.insertAfter(element);
}
}
});
});