表单部分:
<uni-forms ref="registerForm" :rules="registerRules" :modelValue="registerParams" validate-trigger="bind">
<uni-forms-item label="姓名" required name="realname">
<uni-easyinput v-model="registerParams.realname" type="text" placeholder="请输入姓名" maxlength="11" @input="handleRealnameCheck"/>
</uni-forms-item>
<uni-forms-item label="性别" required name="sex" :localdata="sexs">
<uni-data-checkbox v-model="registerParams.sex" :localdata="sexs" />
</uni-forms-item>
<uni-forms-item label="手机号" required name="phone">
<uni-easyinput v-model="registerParams.phone" type="number" placeholder="请输入手机号" maxlength="11" @input="handlePhoneCheck"/>
</uni-forms-item>
</uni-forms>
自定义校验规则:
phone: {
rules: [{
equired: true,
errorMessage: "请输入手机号"
},{
validateFunction:function(rule, value, data, callback) {
var reg=/^1[3456789]\d{9}$/
if (!reg.test(value)) {
callback('请输入正确的手机号')
}else{
callback()
}
}
}]
}
onReady() {
this.$refs.registerForm.setRules(this.registerRules)
}
8***@qq.com
太棒了,找了半天,看到这条终于解决!
2022-01-18 14:38
1***@qq.com
删掉:rules后小程序里正常了,H5验证完全失效,真下头,坑真多啊
2023-03-27 21:02
1***@qq.com
回复 1***@qq.com: 人麻了,之前用过都没问题,今天H5突然不行了
2023-06-30 15:11