angular密码和确认密码的校验

确认密码



passwordChange(value: string){

    const confirmPasswordErrors = this.userPassForm.get('confirmPassword').errors;
    const passwordErrors = this.userPassForm.get('password').errors;
    if (confirmPasswordErrors && (confirmPasswordErrors.hasOwnProperty('pattern') || confirmPasswordErrors.hasOwnProperty('password') )){
      return;
    }
    if ( passwordErrors && (passwordErrors.hasOwnProperty('pattern') || passwordErrors.hasOwnProperty('password'))){
      return;
    }
    if (!this.resetPassWordVo.password || this.resetPassWordVo.password === '' ){
      return;
    }
    if (!this.resetPassWordVo.confirmPassword || this.resetPassWordVo.confirmPassword === '' ){
      return;
    }

    // 上边的校验通过后
    if (this.resetPassWordVo.password === value || this.resetPassWordVo.confirmPassword === value){
      this.userPassForm.get('password').setErrors(null);
      this.userPassForm.get('confirmPassword').setErrors(null);
    }else{
      this.userPassForm.get('password').setErrors({ passwordDiff: '两次输入的密码不一致!'});
      this.userPassForm.get('confirmPassword').setErrors({ passwordDiff: '两次输入的密码不一致!'});
    }

  }

个人博客 蜗牛

你可能感兴趣的:(angular密码和确认密码的校验)