<el-input class="pro_input" v-model="formData.astrict" type="number" step="1" min="0" max="10000" size="mini" @keyup.native="proving1"></el-input>
methods :{
proving1() {
this.formData.astrict=this.formData.astrict.replace(/[^\.\d]/g,''); //清除"数字"和"."以外的字符
this.formData.astrict=this.formData.astrict.replace(/^\./g,''); //验证第一个字符是数字而不是.
this.formData.astrict=this.formData.astrict.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的.
this.formData.astrict=this.formData.astrict.replace(".","$#$").replace(/\./g,"").replace("$#$",".");//只允许输入一个小数点
this.formData.astrict=this.formData.astrict.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
}
}
<input oninput="value=value.replace(/[^0-9\.]/g,'').replace(/^\./g,'').replace(/\.{2,}/g,'.').replace('.','$#$').replace(/\./g,'').replace('$#$','.')" />
标签:数字,formData,小数点,replace,input,astrict,输入
From: https://www.cnblogs.com/vvull/p/17849656.html