'check password strength in angular
This is the code:
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];
}
I get error: Conversion of type 'null' to type 'string' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.ts(2352)
Solution 1:[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:
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | racem triki |
