ant vue from表单验证,用户名、密码、手机校验

<a-form class="user-layout-login" :form="form">
      <a-form-item has-feedback>
        <a-input size="large" type="text" placeholder="用户名" v-decorator="['supplierid', checkRules.supplierid]">
          <a-icon slot="prefix" type="user" />
        </a-input>
      </a-form-item>
      <a-form-item has-feedback>
        <a-input size="large" type="password" placeholder="密码" v-decorator="['password', checkRules.password]">
          <a-icon slot="prefix" type="lock" />
        </a-input>
      </a-form-item>
      <a-form-item has-feedback>
        <a-input size="large" type="password" placeholder="确认密码" v-decorator="['confirmPassword', checkRules.confirmPassword]">
          <a-icon slot="prefix" type="lock" />
        </a-input>
      </a-form-item>
      <a-form-item has-feedback>
        <a-input-group size="large">
          <a-row :gutter="8">
            <a-col :span="5">
              <a-input default-value="+86" :readOnly="true" />
            </a-col>
            <a-col :span="19">
              <a-input v-decorator="['phonenum', checkRules.phonenum]" placeholder="手机号码" />
            </a-col>
          </a-row>
        </a-input-group>
      </a-form-item>
      <a-form-item>
        <drag-verify
          :width="width"
          :height="height"
          :text="text"
          :success-text="successText"
          :background="background"
          :progress-bar-bg="progressBarBg"
          :completed-bg="completedBg"
          :handler-bg="handlerBg"
          :handler-icon="handlerIcon"
          :text-size="textSize"
          :success-icon="successIcon"
          ref="Verify"
        >
        </drag-verify>
      </a-form-item>
      <a-form-item style="margin-top:30px">
        <a-checkbox v-decorator="['remember', { initialValue: true, valuePropName: 'checked' }]">
          <a @click="service">《供应商协同平台服务条款》、《法律声明和隐私政策》</a>
        </a-checkbox>
      </a-form-item>
      <a-form-item style="margin-top:5px">
        <a-button size="large" html-type="submit" type="primary" class="login-button" :disabled="loginBtn" @click="handleSubmit">
          同意条款并注册
        </a-button>
      </a-form-item>
    </a-form>

export default {
  name: 'Login',
  data() {
    return {
      checkRules: {
        supplierid: {
          rules: [
            {
              required: true,
              validator: (rule, value, cbfn) => {
                if (!value) {
                  cbfn('请输入用户名')
                } else if (value) {
                  supplierLogin({ supplierid: value }).then(res => {
                    if (String(res.code) !== '0') {
                      cbfn('用户名不可用')
                    } else {
                      cbfn()
                    }
                  })
                }
              }
            }
          ],
          validateTrigger: 'blur'
        },
        password: {
          rules: [
            {
              required: true,
              validator: (rule, value, cbfn) => {
                if (!value) {
                  cbfn('请输入密码')
                }
                cbfn()
              }
            }
          ],
          validateTrigger: 'change'
        },
        confirmPassword: {
          rules: [
            {
              required: true,
              validator: (rule, value, cbfn) => {
                if (!value) {
                  cbfn('请再一次输入密码')
                } else if (value && value !== this.form.getFieldValue('password')) {
                  cbfn('两次密码不一致')
                }
                cbfn()
              }
            }
          ],
          validateTrigger: 'change'
        },
        phonenum: {
          rules: [
            {
              required: true,
              validator: (rule, value, cbfn) => {
                const regex = /^1[3456789]\d{9}$/
                if (!regex.test(value)) {
                  cbfn('请输入正确格式')
                }
                cbfn()
              }
            }
          ],
          validateTrigger: 'blur'
        }
      },
}}}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值