elementui el-input input box regular limit

1. Only numbers can be entered and the decimal point is 3 digits, and there is only one decimal point. If there is no decimal point after the beginning of 0, it will be replaced with a number, and it will be automatically completed

<el-input
  v-model="value"
  oninput="
    this.value=this.value.replace(/\D*(\d*)(\.?)(\d{0,2})\d*/,'$1$2$3') // 只能输入数字、小数点限制2位
    .replace(/^0+(\d)/, '$1') // 第一位0开头,0后面为数字,则过滤掉,取后面的数字
    .replace(/^\./, '0.') // 如果输入的第一位为小数点,则替换成 0. 实现自动补全
    .match(/^\d*(\.?\d{0,2})/g)[0] || '' // 数字开头、小数点2位
  "
/>

Guess you like

Origin blog.csdn.net/DarlingYL/article/details/129256922