1、纯输入框
方法一:
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'}
]
},
版权声明:本文为weixin_44171757原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。