<> stay util.js Define methods in
Include amount add filter thousandth , Verification amount format, etc
const MoneyTest = /((^[1-9]\d*)|^0)(\.\d{0,2}){0,1}$/; // Amount added in thousandths const
comdify = function (n) { if(!n) return n; let str = n.split('.'); let re =
/\d{1,3}(?=(\d{3})+$)/g; let n1 = str[0].replace(re, "$&,"); return str.length
> 1 && str[1] ? `${n1}.${str[1]}` : `${n1}.00`; }; // Remove the impurities in the thousandth percentile ‘,’ const
delcommafy = function (num){ if(!num) return num; num = num.toString(); num =
num.replace(/,/gi, ''); return num; }; const valdateFn = function (rule,val,cb)
{ setTimeout(() => { if(val) { let inputVal = delcommafy(val); if
(rule.test(inputVal)) { cb() } else { cb(' Only digital amount , Up to two decimal places ') } } cb() }) } //
The verification amount number can be negative const moneyValid = function (rule,val,cb) {
valdateFn(/((^-?[1-9]\d*)|^-?0)(\.\d{0,2}){0,1}$/,val,cb); }; // The number of verification amount cannot be negative
const moneyNValid = function (rule,val,cb) { valdateFn(MoneyTest,val,cb); }; //
Gets the value of the input box const getInputValue = function (el) { let inputVal = el.target.value ||
''; return comdify(delcommafy(inputVal)); };
<> Use in components
stay template in
<el-input v-model.trim="form.pastAdjustFee"
@blur="inputMoney($event,'pastAdjustFee')"></el-input>
stay methods Defined in
data(){ return { form:{ pastAdjustFee:'' } } } methods:{ inputMoney(el,name) {
this.form[name] = getInputValue(el); } }
Technology
Daily Recommendation