0

In .NET Core-6, I have this validation:

.MinimumLength(8).WithMessage("Password must contain at least 8 characters")
.Matches("[A-Z]").WithMessage("Password must contain atleast 1 uppercase letter")
.Matches("[a-z]").WithMessage("Password must contain atleast 1 lowercase letter")
.Matches("[0-9]").WithMessage("Password must contain a number")
.Matches("[^a-zA-Z0-9]").WithMessage("Password must contain non alphanumeric");

I want to convert to a single regex in Angular.

Password must consist of a upper case, special character, lower case and numeric

I used this:

ts:

newPassword: ['', [Validators.required, Validators.minLength(8), Validators.maxLength(50),Validators.pattern('^[ A-Za-z0-9_@./$&#*&=+-]*$')]],

html:

<div *ngIf="isSubmitted && f['newPassword'].errors" class="invalid-feedback">
  <div *ngIf="f['newPassword'].errors?.['required']">New Password is required</div>
  <div *ngIf="f['newPassword'].errors?.['minlength']">New Password must be at least 8 characters</div>
  <div *ngIf="f['newPassword'].errors?.['maxlength']">New Password cannot be more than 50 characters</div>
  <div *ngIf="f['newPassword'].errors?.['pattern']">New Password must have minimum of 8 characters including upper case, lower case, number and special character</div>
</div>

But it is not working.

How do I achieve that?

Thanks

Ayobamilaye
  • 1,099
  • 1
  • 17
  • 46

0 Answers0