<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px"> <el-form-item label="手机号" prop="phone"> <el-input v-model.number="ruleForm.phone"/> </el-form-item> </el-form>
export default { data() { var checkPhone = (rule, value, callback) => { if (!value) { return callback(new Error('手机号不能为空')); } else { const reg = /^1[3|4|5|7|8][0-9]\d{8}$/ console.log(reg.test(value)); if (reg.test(value)) { callback(); } else { return callback(new Error('请输入正确的手机号')); } } }; return { ruleForm: { phone: '' }, rules: { phone: [ {validator: checkPhone, trigger: 'blur'} ] } }; } }