js中填写
$(function() {
validateSysConfigForm();
jQuery.validator.addMethod("validateNum", function (value, element, param) {
var aint = parseInt(value);
return aint > 0 && (aint+"") == value;
}, "请填写正整数(>0)");
});
表单的验证
/**
* 表单验证
*/
function validateSysConfigForm()
{
$('#payMoneyForm').validate({
rules:{
payMoney: {
required: true,
validateNum:true
}
},
messages:{
payMoney: {
required: "请填写停车缴费金额",
validateNum: "请填写正整数(>0)"
}
},
errorElement : 'div',
errorClass : 'help-block',
focusInvalid : false,
ignore : "", highlight : function(e) {
$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
},
success : function(e) {
$(e).closest('.form-group').removeClass('has-error').addClass('has-success');
$(e).remove();
},
errorPlacement : function(error, element) {
if(element.is('.select2')) {
error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
}
else error.insertAfter(element.parent());
}, submitHandler : function(form) { var url = '/base/config/edit.html'; commit(url, '/base/config/editUI.html');
}
});
}