Browse Source

修改密码限制

zs 7 months ago
parent
commit
9eebcada25
1 changed files with 11 additions and 2 deletions
  1. 11 2
      src/views/center/parts/password.vue

+ 11 - 2
src/views/center/parts/password.vue

@@ -1,7 +1,7 @@
 <template>
   <div id="index">
     <el-row>
-      <el-col :span="24" class="main " v-loading="loading">
+      <el-col :span="24" class="main" v-loading="loading">
         <el-col :span="24" class="one">
           <custom-form v-model="form" :fields="fields" :rules="rules" @save="toSave"></custom-form>
         </el-col>
@@ -28,8 +28,17 @@ const fields = ref([
   { label: '新密码', model: 'password', type: 'password' },
   { label: '确认新密码', model: 'ispassword', type: 'password' }
 ])
+const passwordValValidate = (rule, value, callback) => {
+  if (!value) {
+    return callback(new Error('请输入密码'))
+  } else if (/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[._~!@#$^&*])[A-Za-z0-9._~!@#$^&*]{8,16}$/g.test(value)) {
+    return callback()
+  } else {
+    return callback(new Error('请输入包含英文字母大小写、数字和特殊符号的 8-16 位组合'))
+  }
+}
 const rules = ref({
-  password: [{ required: true, message: '请输入新密码' }],
+  password: [{ required: true, validator: passwordValValidate }],
   ispassword: [
     { required: true, message: '请输入确认新密码' },
     {