Vue+elementUI el-input输入框手机号校验
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
免费下载资源
·
1.限制input框内只能输入数字,且为11位
type="number" // 数字类型
// maxlength属性对type="number"类型的输入框无效
οninput="if(value.length>11)value=value.slice(0,11)"
2.对输入手机号做校验
<el-form :model="dialogData" :rules="addAddressRules" ref="dialogData">
<el-form-item label="" prop="phone">
<el-input
placeholder="请输入电话号码"
v-model="dialogData.phone"
type="number"
oninput="if(value.length>11)value=value.slice(0,11)"
onkeyup="this.value = this.value.replace(/[^\d]/g,'');"
size="large"
clearable
>
</el-input>
</el-form-item>
</el-form>
data() {
var checkPhone = (rule, value, callback) => { // 手机号验证
if (!value) {
return callback(new Error('手机号不能为空'));
} else {
const reg = /^1[3456789]\d{9}$/
if (reg.test(value)) {
callback();
} else {
return callback(new Error('请输入正确的手机号'));
}
}
};
return {
dialogData: {
phone:'',
},
addAddressRules: {
phone: [
{ required: true, message: "请输入正确手机号", trigger: "blur" },
{validator: checkPhone, trigger: 'blur'}
],
},
}
},
实现效果:
GitHub 加速计划 / eleme / element
54.06 K
14.63 K
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:3 个月前 )
c345bb45
7 个月前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 7 个月前
更多推荐
已为社区贡献20条内容
所有评论(0)