【问题标题】:check password strength in angular以角度检查密码强度
【发布时间】:2021-11-23 13:24:40
【问题描述】:

这是代码:

export class AppComponent {
   title = 'password-strength-angular';

   public account = {
      password: <string>null
   };
   public barLabel: string = "Password strength:";
   public myColors = ['#DD2C00', '#FF6D00', '#FFD600'];
   public thresholds = [90, 75, 45, 25];
}

我收到错误:将“null”类型转换为“string”类型可能是一个错误,因为这两种类型都没有与另一种充分重叠。如果这是故意的,请将表达式转换为 'unknown' first.ts(2352)

【问题讨论】:

  • 你为什么不把它设置为空字符串''。密码是字符串类型,所以默认值为空字符串。
  • 请澄清您的具体问题或提供更多详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: angular typescript passwords


【解决方案1】:
validateData(field:any) {
    switch (field) {
      case 'userName':
        if (this.user.userName == '')
          this.errorMessages.userName =
            "le nom d'utilisateur ne peut pas être vide";
        else this.errorMessages.userName = '';
        break;
      case 'password':
        if (this.user.password == '')
          this.errorMessages.password =
            'le mot de passe ne peut pas être vide';
          else if(! this.user.password.match( /[0-9]/g)){
            this.errorMessages.password =
            'mot de passe doit contenir au minimum un chiffre';
          }
          else if(! this.user.password.match( /[a-z]/g)){
            this.errorMessages.password =
            'mot de passe doit contenir au minimum une lettre minuscule';
          }
          else if(! this.user.password.match( /[A-Z]/g)){
            this.errorMessages.password =
            'mot de passe doit contenir au minimum une lettre majuscule';
          }
          else if(! (this.user.password.length >= 10)){
            this.errorMessages.password =
            'mot de passe doit contenir au minimum 10 caractères';
          }
        else this.errorMessages.password = '';
        break;
      default:
    }
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-08
    • 2010-11-26
    • 2014-10-26
    • 2012-06-16
    • 1970-01-01
    • 1970-01-01
    • 2013-05-18
    • 2011-09-03
    相关资源
    最近更新 更多