el-input 限制输入框只能输入数字和小数

方法一:

oninput =“value=value.replace(/[^\d]/g,‘’)” //只能输入数字

oninput =“value=value.replace(/[^0-9.]/g,‘’)” //只能输入数字和小数

<el-input v-model="sjje" oninput ="value=value.replace(/[^0-9.]/g,'')" class="money sjje">
    <span slot="suffix">/ 元 </span>
</el-input>                           

方法二:

    <el-input v-model="sjje" class="money sjje" @input="inputChange">
      <span slot="suffix">/ 元 </span>
    </el-input>

    inputChange(val) {
      this.sjje = this.sjje.replace(/[^0-9.]/g, '')
    }

2、form表单输入框

<el-form ref="userform" rules="rules" :model="form" label-width="110px">
    <el-row>
        <el-form-item label="年龄:" prop="age">
            <el-input v-model="form.age"></el-input>
        </el-form-item>
    </el-row>
</el-form>

rules:{
  age:[
    { required: true, message: '年龄不能为空', trigger: 'blur'},
    {pattern: /^[0-9]*$/, message: '年龄需为数字', trigger: 'blur'}
  ]
},

来源于:https://blog.csdn.net/weixin_44171757/article/details/102391297

posted @ 2022-07-22 09:07  haha-uu  阅读(7854)  评论(0编辑  收藏  举报