vue + element in el-input box restrict only numbers and decimal

Only personal experience, we hope to help people in need.

The first written word does not say directly on the code.

<el-input @keyup.native="proving(index)" v-model="item.Price"></el-input>
// only enter numbers and only one decimal 
            Proving (E) {
           // this.form.skus [E] is the value of input .price the  
                // first replace all non-digital, and digital addition. 
                The this .form .skus [E] = .price the this .form.skus [E] .Price.replace (/ [^ \ D.] / G, '' );
                 // must ensure that the first digital instead. 
                the this .form .skus [E] = .price the this .form.skus [E] Price.replace (/^\./ G, '' );
                 // ensure that only one without a plurality of occurrence.. 
                the this .form.skus [E ] = .price the this .form.skus [E] .Price.replace (/ \ {2,} / G, ''. );
                 // guaranteed only once, but twice or more can not occur. 
                the this .form.skus [e] .Price =this.form.skus[e].Price.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.');
                let index = -1
                for (let i in this.form.skus[e].Price) {
                    if (this.form.skus[e].Price[i] === '.') {
                        index = i
                    }
                    if (index !== -1) {
                        if (i - index > 1) {
                            this.form.skus[e].Price = this.form.skus[e].Price.substring(0, this.form.skus[e].Price.length - 1)
                        }
                    }
                }
            },

Guess you like

Origin www.cnblogs.com/zm-97/p/12076892.html