Vue.js judges how to use regular expressions for input input

for example, the following code:

< input type= "text" v muri model = "sellPrice" >
< input type= "text" v muri model = "buyVolume" >

reg:/ ^ [0-9] + (. [0-9] {1 Magazine 8})? $/
reg1:/ [0-9] dudes /

watch: {

    buyPrice:function(){
       
    },
    sellPrice:function(){
        let a = this.sellPrice;
        this.sellPrice = a.match(this.reg,"");
    },
    buyVolume:function(){
        this.buyVolume = this.buyVolume.match(/[0-9]\d*/,"");
       
    },
    sellVolume:function(){
        this.sellVolume = this.sellVolume.match(/[0-9]\d*/,"");
    }
}

Price could not succeed.
Why does sellVolume succeed but report this.sellVolume.match is not a function

Apr.11,2021

I usually write to encapsulate the regular expression into a method, and then verify the input data when I enter the data. For example, I recently worked on a project to format the input bank card number.

//
export function isBankNumber(str) {
    const reg = /^([1-9]{1})(\d{15}|\d{18})$/
    return reg.test(str)
}
//input
if (!isBankNumber(vm.temp.bankAccount.replace(/\s+/g,""))) {
                vm.showToast = true;
                vm.toastTitle = "';
                vm.toastType = "text';
                vm.toastWidth = '200px';
                return;
  }

Why do you want to write it in watch? you can write it in computed, or you can write a filter.


match gets an array, so the error and regularity should be / ^ [0-9] d $| (^ [0-9] +. [0-9] {0jue 8}) /, watch test data is fine. On the contrary, it will be troublesome to use computed


multiple modes
watch

computed: {
    value: {
        set() {
        },
        get() {
        }
     }
     }
Menu