checkPassword(password) {
 if (typeof password !== 'string' || password === '') {
   return {
     success: false,
     message: '请输入新密码'
   }
 }
 const errors = []
 if (!/[A-Z]/.test(password)) {
   errors.push('大写字母')
 }
 if (!/[a-z]/.test(password)) {
   errors.push('小写字母')
 }
 if (!/[0-9]/.test(password)) {
   errors.push('数字')
 }
 if (!/[^\w\s]/.test(password)) {
   // 非空格、制表符、换页符
   errors.push('特殊字符')
 }
 if (errors.length > 0) {
   return {
     success: false,
     message: `缺少${errors.join(',')}`
   }
 }
 if (/[\s]/.test(password)) {
   // 非空格、制表符、换页符
   return {
     success: false,
     message: '不允许空字符'
   }
 }
 if (password.length < 12) {
   return {
     success: false,
     message: '长度至少12位'
   }
 } else if (password.length > 24) {
   return {
     success: false,
     message: '长度至多24位'
   }
 }
 if (!/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[^\w\s]).{8,24}$/.test(password)) {
   return {
     success: false,
     message: '校验失败'
   }
 }
 return {
   success: true
 }
}

全部评论