验证数据提供参考
$("#goodsForm").bootstrapValidator({ message: 'This value is not valid', feedbackIcons: { valid: 'glyphicon', invalid: 'glyphicon', validating: 'glyphicon' }, fields: { goods_code: { validators: { notEmpty: { message: __("产品编号不能为空") }, regexp: { regexp: /^[\w\s]+$/, message: __("产品编号只能为字母和数字") }, stringLength: { min: 2, max: 50, message: __('产品编号长度为2~50位') } } }, goods_name: { validators: { notEmpty: { message: __("产品名称不能为空") }/* , stringLength: { min: 1, max: 20, message: __('产品名称长度为1~20位') } */ } }, goods_price: { validators: { notEmpty: { message: __("零售价格不能为空") }, regexp: { regexp: /^(0(?:[.](?:[0-9]\d?|0[0-9]))|[0-9]\d*(?:[.]\d{1,2}|$))$/, message: __('请输入数字并且小数点后2位') }, between: { min: 0, max: sysParameter.unit_price*10000, message: __('零售价格最低为0且不能超过') + sysParameter.unit_price + __('万') } } }, goods_cost: { validators: { regexp: { regexp: /^(0(?:[.](?:[0-9]\d?|0[0-9]))|[0-9]\d*(?:[.]\d{1,2}|$))$/, message: __('请输入数字并且小数点后2位') }, between: { min: 0, max: sysParameter.unit_price * 10000, message: __('参考进价最低为0且不能超过' )+ sysParameter.unit_price+ __('万') } } }, goods_vip_price: { validators: { regexp: { regexp: /^(0(?:[.](?:[0-9]\d?|0[0-9]))|[0-9]\d*(?:[.]\d{1,2}|$))$/, message: __('请输入数字并且小数点后2位') }, between: { min: 0, max: sysParameter.unit_price * 10000, message: __('产品会员价最低为0且不能超过') + sysParameter.unit_price+ __('万') } } }, goods_stock: { validators: { notEmpty: { message: __("库存不能为空") }, regexp: { min: 1, regexp: /^[0-9]*[1-9][0-9]*$/, message: __('请输入正整数') } } } } }).on("success.form.bv", function (e) { e.preventDefault(); var isSubmit = true; var data = $("#goodsForm").serializeObject(); var isSubmit = true; if ($("#goods_code").val() == "") { alertError(__("产品编号不能输入为空")); isSubmit = false; return; } //是否积分 if ($("#is_points").prop("class") == "active") { data.goods_is_points = 1; } else { data.goods_is_points = 0; } //是否折扣 if ($("#is_discount").prop("class") == "active") { data.goods_is_discount = 1; } else { data.goods_is_discount = 0; } //验证积分 isSubmit = obj.changeFun(1); if (!isSubmit) { if (data.goods_is_points == 0) { return false; } } //验证折扣 isSubmit = obj.changeFun(2); if (!isSubmit) { if (data.goods_is_discount == 0) { return false; } } if ($("#goods_cat").val() == null) { alertError(__("请先添加产品类别")); isSubmit = false; return; } if (isSubmit) { if (($("#is_discount").prop("class") == "active") && $("#goods_vip_price").val() > 0) { alertError(__("【产品会员价】和【最低折扣】,只允许选择一种折扣方式,请重新输入!")); }else { if(goods_id) { var url = SYS.CONFIG.index_url + '?ctl=Goods_Base&met=edit&typ=json'; data.goods_id = goods_id; }else{ var url = SYS.CONFIG.index_url + '?ctl=Goods_Base&met=add&typ=json'; } $.ajax({ url: url, type: 'post', data: data, dataType: "json", success: function (data) { if (data && data.status == 200) { alertMessage(__("操作成功")); setTimeout(function () { window.location.href = SYS.CONFIG.index_url + '?ctl=Goods_Base&met=index&typ=e'; }, 1000); } else { alertError(data.msg); } } }); } } }); },