当输入框只允许输入小数的el-input正则

内容分享1个月前发布
0 0 0

<el-input v-model=”balanceRechargePrices” placeholder=”请输入充值金额” @input=”handleInput” @focus=”focusInput”></el-input>
const handleInput = (value: string) => {
console.log( value , value);
const restrictedValue = value.replace(/[^0-9.]/g, ).replace(/^./, );
// 限制小数点后最多两位
let limitedValue = restrictedValue.split( . ).length > 1 ? ${restrictedValue.slice(0, restrictedValue.indexOf( . ) + 3)} : restrictedValue;
limitedValue = limitedValue.replace(/(..*)./g, $1 );
balanceRechargePrice.value = limitedValue ? limitedValue : 0;
balanceRechargePrices.value = limitedValue ? limitedValue : ;
};
const focusInput = () => {
balanceRechargePrice.value = balanceRechargePrices.value;
};

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
none
暂无评论...