|  |  |  | 
|---|
|  |  |  | show-password></el-input> | 
|---|
|  |  |  | </el-form-item> | 
|---|
|  |  |  | <el-form-item label="新密码" prop="newPwd" required> | 
|---|
|  |  |  | <el-input v-model="changePwdData.form.newPwd" type="password" placeholder="请输入新密码,密码需包含字母、数字及特殊字符中的至少两种" | 
|---|
|  |  |  | <el-input v-model="changePwdData.form.newPwd" type="password" placeholder="请输入新密码,至少包括数字、大写字母、小写字母、特殊字符中的三种字符,且至少8位数" | 
|---|
|  |  |  | maxlength="20" show-password></el-input> | 
|---|
|  |  |  | </el-form-item> | 
|---|
|  |  |  | <!-- <div style="font-size: 12px;color:#999999">密码需包含字母、数字及特殊字符中的至少两种</div> --> | 
|---|
|  |  |  | 
|---|
|  |  |  | if (!value) { | 
|---|
|  |  |  | callback(new Error('请输入密码')) | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | const lengthValid = /^.{6,20}$/.test(value) | 
|---|
|  |  |  | const hasLetter = /[a-zA-Z]/.test(value) | 
|---|
|  |  |  | const hasNumber = /[0-9]/.test(value) | 
|---|
|  |  |  | const hasSpecial = /[!@#$%^&*(),.?":{}|<>]/.test(value) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const typesCount = [hasLetter, hasNumber, hasSpecial].filter(Boolean).length | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!lengthValid) { | 
|---|
|  |  |  | callback(new Error('密码长度需为6到20个字符')) | 
|---|
|  |  |  | } else if (typesCount < 2) { | 
|---|
|  |  |  | callback(new Error('密码需包含字母、数字及特殊字符中的至少两种')) | 
|---|
|  |  |  | // const lengthValid = /^.{6,20}$/.test(value) | 
|---|
|  |  |  | // const hasLetter = /[a-zA-Z]/.test(value) | 
|---|
|  |  |  | // const hasNumber = /[0-9]/.test(value) | 
|---|
|  |  |  | // const hasSpecial = /[!@#$%^&*(),.?":{}|<>]/.test(value) | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // const typesCount = [hasLetter, hasNumber, hasSpecial].filter(Boolean).length | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // if (!lengthValid) { | 
|---|
|  |  |  | //   callback(new Error('密码长度需为6到20个字符')) | 
|---|
|  |  |  | // } else if (typesCount < 2) { | 
|---|
|  |  |  | //   callback(new Error('密码需包含字母、数字及特殊字符中的至少两种')) | 
|---|
|  |  |  | // } else { | 
|---|
|  |  |  | //   callback() // 验证通过 | 
|---|
|  |  |  | // } | 
|---|
|  |  |  | let typeCount = 0; | 
|---|
|  |  |  | if (/[a-z]/.test(value)) typeCount++; // 小写字母 | 
|---|
|  |  |  | if (/[A-Z]/.test(value)) typeCount++; // 大写字母 | 
|---|
|  |  |  | if (/\d/.test(value)) typeCount++;    // 数字 | 
|---|
|  |  |  | if (/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(value)) typeCount++; // 特殊字符 | 
|---|
|  |  |  | if (typeCount >= 3) { | 
|---|
|  |  |  | callback() | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | callback() // 验证通过 | 
|---|
|  |  |  | callback(new Error('至少包括数字、大写字母、小写字母、特殊字符中的三种字符,且至少8位数')) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }, | 
|---|