Vue中 修改密码与重复密码的校验

<el-dialog title="修改登录密码" :visible.sync="newPwdVisible" center>
  <el-form :model="newForm" ref="newForm" :rules="ruleValidate">
     <el-form-item label="新密码" prop="newPwd">
        <el-input v-model="newForm.newPwd" type="password" clearable placeholder="请输入6-16位数字、字母(区分大小写)、符号的组合"></el-input>
     </el-form-item>
     <el-form-item label="再次输入新密码" prop="newAgainPwd">
        <el-input v-model="newForm.newAgainPwd" type="password" clearable placeholder="请再次输入新密码"></el-input>
     </el-form-item>
  </el-form>
  <div slot="footer" class="dialog-footer">
     <el-button @click="newPwdVisible = false">取 消</el-button>
     <el-button type="primary" @click="saveInfo">确 定</el-button>
  </div>
</el-dialog>


data () {          // 新密码校验       const pwdCheck = async(rule, value, callback) => {      // const reg = /^(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[^A-Za-z0-9])).{6,16}$/;      const reg = /^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{6,16}$/;       if (value !== '') {         if (value.length < 6) {           return callback(new Error('新密码至少输入6位'))         } else if (value.length > 16) {           return callback(new Error('密码最长不能超过16位'))         } else if (!reg.test(value)) {           return callback(new Error('密码输入有误,请检查格式是否正确!'))         } else {           callback()         }       }else{         return callback(new Error('新密码不能为空'))        }      }      // 重复密码验证     const pwdAgainCheck = async(rule, value, callback) => {       if (value.length < 1) {         return callback(new Error('重复密码不能为空!'));       } else if(this.newForm.newPwd !== this.newForm.newAgainPwd){         return callback(new Error('两次输入密码不一致!'));      }else{        callback()      }    }   return {
newForm: { 
newPwd: '',
newAgainPwd: ''
},
newPwdVisible: false,
ruleValidate: {
      newPwd: [ { required: true, validator: pwdCheck, trigger: 'blur' } ],       newAgainPwd: [ { required: true, validator: pwdAgainCheck, trigger: 'blur' } ]
}
  } }

  

上一篇:JavaScript(JS) array.filter(callback[, thisObject])


下一篇:[Oauth] Oauth2.0中的授权码模式