elementUI中的el-form 正则校验 校验正整数
vue使用element el-form认证正整数<template><div><el-formref="phoneDialogForm":rules="rules":model="phoneData"label-position="right"label-width="100px"><el-form-item label="正整数认证" prop="ph
·
vue使用element el-form认证正整数
<template>
<div>
<el-form
ref="phoneDialogForm"
:rules="rules"
:model="phoneData"
label-position="right"
label-width="100px"
>
<el-form-item label="正整数认证" prop="phone" style="width: 300px">
<el-input v-model="phoneData.phone" maxlength="11" />
</el-form-item>
</el-form>
</div>
</template>
<script>
export default {
data() {
return {
phoneData: {
sendcode: "",
},
rules: {
phone: [
{
validator: (rule, value, callback) => {
if (/^(?:[1-9]\d*)$/.test(value) == false) {
callback(new Error("请输入正整数"));
} else {
callback();
}
},
trigger: "change",
},
],
code: [{ required: true, message: "请输入验证码", trigger: "blur" }],
},
};
},
created() {},
methods: {},
};
</script>
更多推荐
已为社区贡献10条内容
所有评论(0)