User password regular expression to validate consecutive repeating characters

This commit is contained in:
Jose Alberto Hernandez
2025-03-27 22:16:59 -05:00
parent 7bd2bf8f0f
commit 7bd6146984
11 changed files with 17 additions and 82 deletions
+3 -2
View File
@@ -1,5 +1,6 @@
import { Injectable } from '@angular/core';
import { AbstractControl, ValidationErrors, ValidatorFn, Validators } from '@angular/forms';
import { environment } from 'environments/environment';
import { Subscription } from 'rxjs';
@Injectable({
@@ -7,14 +8,14 @@ import { Subscription } from 'rxjs';
})
export class PasswordsUtility {
// password regex pattern
public static PASSWORD_REGEX = '^(?!.*(.)\\1)(?!.*\\s)(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^\\w\\s]).{12,50}$';
public static PASSWORD_REGEX = '^(?!.*(.)\\1{1,})(?!.*\\s)(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^\\w\\s]).{12,50}$';
public getPasswordValidators(): ValidatorFn[] {
return [
Validators.required,
Validators.pattern(PasswordsUtility.PASSWORD_REGEX),
Validators.maxLength(50),
Validators.minLength(8)];
Validators.minLength(environment.minPasswordLength)];
}
/**