<el-input
type="text"
v-model.trim="ruleForm2.marketPrice"
maxlength="10"
@keyup.native="ruleForm2.marketPrice =ruleForm2.marketPrice = ruleForm2.marketPrice.replace(/[^\d.]/g,'');
ruleForm2.marketPrice = ruleForm2.marketPrice.replace(/\.{2,}/g,'.');
ruleForm2.marketPrice = ruleForm2.marketPrice.replace(/^\./g,'');
ruleForm2.marketPrice = ruleForm2.marketPrice.replace('.','$#$').replace(/\./g,'').replace('$#$','.');
ruleForm2.marketPrice = ruleForm2.marketPrice.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');
"
></el-input>
function clearNoNum(obj)orm
{input
//先把非數字的都替換掉,除了數字和.io
obj.value = obj.value.replace(/[^\d.]/g,"");function
//保證只有出現一個.而沒有多個.model
obj.value = obj.value.replace(/\.{2,}/g,".");im
//必須保證第一個爲數字而不是.di
obj.value = obj.value.replace(/^\./g,"");數字
//保證.只出現一次,而不能出現兩次以上
obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
//只能輸入兩個小數
obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');
}