vue使用element el-form认证正整数

<template>
  <div>
    <el-form
      ref="phoneDialogForm"
      :rules="rules"
      :model="phoneData"
      label-position="right"
      label-width="100px"
    >
      <el-form-item label="正整数认证" prop="phone" style="width: 300px">
        <el-input v-model="phoneData.phone" maxlength="11" />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      phoneData: {
        sendcode: "",
      },
      rules: {
        phone: [
          {
            validator: (rule, value, callback) => {
              if (/^(?:[1-9]\d*)$/.test(value) == false) {
                callback(new Error("请输入正整数"));
              } else {
                callback();
              }
            },
            trigger: "change",
          },
        ],
        code: [{ required: true, message: "请输入验证码", trigger: "blur" }],
      },
    };
  },
  created() {},
  methods: {},
};
</script>
Logo

前往低代码交流专区

更多推荐