el-input: Dynamically clear the values that do not comply with the regular check and retain only the values that match

 

<el-input v-model="form.profit" placeholder="请输入授权专利新增利润" @input="handleInput" clearable />


/**
     * 不符合正则校验,清空
     */
    const handleInput = () => {
        if (form.value.profit) {
            if (!/^\d*\.?\d*$/.test(form.value.profit)) {
                // 把不符合正则的值删除,保留符合正则的值
                form.value.profit = form.value.profit.replace(/[^\d.]/g, "");
            }
        }
    };

Guess you like

Origin blog.csdn.net/m0_58293192/article/details/133878547