m***@163.com
m***@163.com
  • 发布:2022-01-11 10:59
  • 更新:2022-01-11 11:09
  • 阅读:1944

uni-app小程序表单校验只生效1次

分类:uni-app

表单部分:
<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)
}

2022-01-11 10:59 负责人:无 分享
已邀请:
m***@163.com

m***@163.com (作者)

问题解决了,onReady中做了绑定,表单的 :rules="registerRules" 删除掉就OK了

  • 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

该问题目前已经被锁定, 无法添加新回复