美文网首页
Vue输入框el-input的输入格式限制

Vue输入框el-input的输入格式限制

作者: 前端阿峰 | 来源:发表于2020-07-12 00:16 被阅读0次

***限制数字

先把非数字的都替换掉,除了数字和.
this.rateParams.k2cAllocateRatio = this.rateParams.k2cAllocateRatio.replace(/[^\d.]/g,"");
保证只有出现一个.而没有多个.
this.rateParams.k2cAllocateRatio = this.rateParams.k2cAllocateRatio.replace(/\.{2,}/g,".");
必须保证第一个为数字而不是.
this.rateParams.k2cAllocateRatio = this.rateParams.k2cAllocateRatio.replace(/^\./g,"");
保证.只出现一次,而不能出现两次以上
this.rateParams.k2cAllocateRatio = this.rateParams.k2cAllocateRatio.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
只能输入两个小数
this.rateParams.k2cAllocateRatio = this.rateParams.k2cAllocateRatio.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');
限制数字大小
this.rateParams.k2cAllocateRatio = this.rateParams.k2cAllocateRatio>100?100:(this.rateParams.k2cAllocateRatio);

相关文章

网友评论

      本文标题:Vue输入框el-input的输入格式限制

      本文链接:https://www.haomeiwen.com/subject/jmgwcktx.html