//验证手机号
  checkAccount(rule, value, callback) {
    //与表单数据进行关联
      const form = this.props.form;
      //正则用//包起来
      var regex = /^((\+)?86|((\+)?86)?)0?1[3458]\d{9}$/; 
      if (value) {
        //react使用正则表达式变量的test方法进行校验,直接使用value.match(regex)显示match未定义
        if (regex.test(value)) { 
          callback();
        } else { 
          callback('请输入正确的手机号码!');
        }
      } else {
        //这里的callback函数会报错
      }
    },
<FormItem
                {...formItemLayout}
                label="手机号:"
                hasFeedback
              >
                {getFieldDecorator('mobile', {
                  rules: [{type:'string', required: true, message: '请输入手机号码!' },{
                    //这里input内的输入内容进行绑定函数即可,在Input里面无需进行函数绑定开使用验证(红色部分)
                    validator: this.checkAccount,
                  }],
                })(
<Input style={{ width: 180 }} onBlur={this.checkAccount} /> )} </FormItem>

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
  • 2022-02-03
  • 2022-01-11
猜你喜欢
  • 2022-12-23
  • 2021-12-05
  • 2021-07-25
  • 2021-11-27
  • 2022-02-05
  • 2022-12-23
相关资源
相似解决方案