9***@qq.com
9***@qq.com
  • 发布:2021-05-24 15:06
  • 更新:2021-05-24 15:06
  • 阅读:348

input使用正则不生效

分类:uni-app
js
<input type="text" v-model="number" @input="onlyNumber(this)"  :focus="true" maxlength="10" />  

onlyNumber(number){  
                console.log(this.number)  
                let t = this.number.charAt(0);  
                this.number = this.number.replace(/[^\d\.\-]/g,'');  
                this.number = this.number.replace(/^0\d[0-9]*/g,'');   
                this.number =this.number.replace(/^\./g,'');  
                this.number =this.number.replace(/\.{2,}/g,'.');  
                this.number = this.number.replace('.','$#$').replace(/\./g,'').replace('$#$','.');   
                this.number = this.number.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');  
                if(t == '-'){ return; }  

            }  
2021-05-24 15:06 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复