Bladeren bron

注册增加校验规则

changjiaming 11 uur geleden
bovenliggende
commit
1f63b95947
3 gewijzigde bestanden met toevoegingen van 26 en 3 verwijderingen
  1. BIN
      2024-11-27-test.7z
  2. 1 1
      src/styles/element/message.scss
  3. 25 2
      src/views/login/components/RegisterContent.vue

BIN
2024-11-27-test.7z


+ 1 - 1
src/styles/element/message.scss

@@ -8,5 +8,5 @@
   min-width: auto !important;
   top: 80px !important;
   padding: 14px !important;
-  z-index: 9999 !important;
+  z-index: 99999 !important;
 }

+ 25 - 2
src/views/login/components/RegisterContent.vue

@@ -58,6 +58,26 @@ export default {
     VerificationCode: () => import('@/components/VerificationCode/index.vue')
   },
   data() {
+    const validatePhone = (rule, value, callback) => {
+      if (!value) {
+        callback(new Error('请输入手机号'))
+      } else if (value.length !== 11 || !/^\d{11}$/g.test(value)) {
+        callback(new Error('手机号格式有误'))
+      } else {
+        callback()
+      }
+    }
+    const validateName = (rule, value, callback) => {
+      if (!value) {
+        callback(new Error('请输入会员名称'))
+      } else if (value.length < 6 || value.length > 16) {
+        callback(new Error('会员名称必须是6-16位数字和字母组合'))
+      } else if (/^([a-zA-Z]+\d+$)|(\d+[a-zA-Z]+$)/g.test(value)) {
+        callback()
+      } else {
+        callback(new Error('会员名称必须是6-16位数字和字母组合'))
+      }
+    }
     return {
       loading: false,
       ruleForm: {
@@ -72,10 +92,13 @@ export default {
         // provinceCityIds: []
       },
       rules: {
-        userName: [{ required: true, message: '请输入会员名称', trigger: 'blur' }],
+        userName: [{ required: true, message: '请输入会员名称', trigger: 'blur' },
+          { validator: validateName, trigger: 'blur' }],
         password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
         confirmPassword: [{ required: true, message: '请输入确认密码', trigger: 'blur' }],
-        phoneNumber: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
+        phoneNumber: [{ required: true, message: '请输入手机号', trigger: 'blur' },
+          { validator: validatePhone, trigger: 'blur' }
+        ],
         code: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
       },
       regionList: []