vue 表單驗證調後臺數據驗證

const validateorderPrice = (rule, value, callback) => {
              //必須包含大小寫字母、數字、特殊字符長度再9-16位之間
              var regex = new RegExp("(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^0-9]).{8,16}");
              if (value === "") {
                callback(new Error("請輸入服務費,不能爲空"));
              }else {
                //銷售價不能超過(-5% < 服務費 < +15%)
                  getSalePrice(this.carProduct.id,this.formCar.carBasicInfo.id,this.carProduct.canalId,this.carProduct.insurerId).then(response => {
                    if(response.data!=undefined){
                      var maxSalesPrice = response.data.salesPrice*1.15;
                      var minSalesPrice = response.data.salesPrice*0.95;
                      if(value>maxSalesPrice || value < minSalesPrice){
                        console.log("銷售價不能超過(-5% < 服務費 < +15%)");
                        callback(new Error('服務費不能超過['+maxSalesPrice+'],且不能低於['+minSalesPrice+']'))
                      }
                    }
                  });

                //callback();
              }
            };



orderPrice: [
                        //{required: true, message: "服務費不能爲空", trigger: "blur"},
                        {required: true, validator: validateorderPrice, trigger: "blur" }
                    ],

  

orderPrice: [
                        //{required: true, message: "服務費不能爲空", trigger: "blur"},
                        {required: true, validator: validateorderPrice, trigger: "blur" }
                    ],
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章