i have attached my code below .im facing problem in adding password mismatch validation.im not getting validation error if i type mismatching password
register.component.html
<div class="form-group row mt-3">
<label class="col-md-4 col-lg-4 text-center">UserName:<span style="color:red">*</span></label>
<input kendoTextBox required type="text" class=" col-md-6 col-lg-6 form-control " placeholder="Enter Your UserName " formControlName="username"/>
<div *ngIf="(submitted||f2.username.touched) && f2.username.invalid" class="error-msg">
<div *ngIf="f2.username.errors.required">UserName is required</div>
</div> </div>
<div class="form-group row">
<label class="col-md-4 col-lg-4 text-center">Password:<span style="color:red">*</span></label>
<input kendoTextBox type="password" required class=" col-md-6 col-lg-6 form-control " placeholder="Enter Your passowrd " formControlName="password"/>
<div *ngIf="(submitted||f2.password.touched) && f2.password.invalid" class="error-msg">
<div *ngIf="f2.password.errors.required">password is required</div>
<div *ngIf="f2.password.errors.minlength">minimum of 6 characters required</div>
</div>
</div>
<div class="form-group row">
<label class="col-md-4 col-lg-4 text-center">ConfirmPassword:
<span style="color:red">*</span></label>
<input kendoTextBox required type="password" class=" col-md-6 col-lg-6 form-control " placeholder="Enter Your new password " formControlName="confirmpassword"/>
<div *ngIf="(submitted||f2.confirmpassword.touched) && f2.confirmpassword.invalid" class="error-msg">
<div *ngIf="f2.confirmpassword.errors.required"> confirm password is required</div> <div *ngIf="f2.confirmpassword.errors.minlength">minimum of 6 characters required
</div>
<div class="error-msg" *ngIf="f2.errors?.mismatch && (f2.controls['confirmpassword'].required || f2.controls['confirmpassword'].touched)">
Passwords don't match.
</div>
</div>
</div>
enter code here
registercomponent.ts file
here i have used formBuilder.other things are working fine ,only validation for mismatching not working
this.registerForm3 = this.formBuilder.group({
username:['', Validators.required],
password: ['', [Validators.required, Validators.minLength(6)]],
confirmpassword:['', [Validators.required, Validators.minLength(6)]],
},
{validator: this.passwordMatchValidator},
);
passwordMatchValidator(frm: FormGroup) {
eturn frm.controls['password'].value ===
frm.controls['confirmpassword'].value ? null : {'mismatch': true};
}
get f2() {
return this.registerForm3.controls;
}