angular密码和确认密码的校验

Angular admin 4个月前 (08-17) 193次浏览 0个评论 扫描二维码

确认密码

<input nz-input formControlName="password" (ngModelChange)="passwordChange($event)" [(ngModel)]="resetPassWordVo.password" required type="password" autocomplete="off">
<input nz-input formControlName="confirmPassword" (ngModelChange)="passwordChange($event)" [(ngModel)]="resetPassWordVo.confirmPassword" required type="password" autocomplete="off">
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: '两次输入的密码不一致!'});
    }

  }

codeobj , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:angular密码和确认密码的校验
喜欢 (0)
[a37free@163.com]
分享 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址