Angular Validation Password and Confirm Password

By Hardik Savani | March 18, 2020 | Category : Angular

I am going to show you example of password and confirm password validation in angular reactive form. this example will help you angular password match validation. you can see password and confirm password validation in angular reactive form. it's simple example of password and confirm password validation in angular 8.

You can use password and confirm password validation in angular 6, angular 7, angular 8, angular 9, angular 10 and angular 11 application.

I will give you full example of how to add match password validation in angular application. we will add two textbox with password and confirm password in angular using reactive form. we will create our custom ConfirmedValidator class for checking match validation. you can also see bellow preview for validation.



<div class="container">

<h1>Angular Validation Password and Confirm Password -</h1>

<form [formGroup]="form" (ngSubmit)="submit()">

<div class="form-group">

<label for="password">Password</label>






<div *ngIf="f.password.touched && f.password.invalid" class="alert alert-danger">

<div *ngIf="f.password.errors.required">Password is required.</div>



<div class="form-group">

<label for="confirm_password">Confirm Password</label>






<div *ngIf="f.confirm_password.touched && f.confirm_password.invalid" class="alert alert-danger">

<div *ngIf="f.confirm_password.errors.required">Password is required.</div>

<div *ngIf="f.confirm_password.errors.confirmedValidator">Password and Confirm Password must be match.</div>



<button class="btn btn-primary" type="submit" [disabled]="!form.valid">Submit</button>




import { Component } from '@angular/core';

import { FormBuilder, FormGroup, FormControl, Validators} from '@angular/forms';

import { ConfirmedValidator } from './confirmed.validator';


selector: 'app-root',

templateUrl: './app.component.html',

styleUrls: ['./app.component.css']


export class AppComponent {

form: FormGroup = new FormGroup({});

constructor(private fb: FormBuilder) {

this.form ={

password: ['', [Validators.required]],

confirm_password: ['', [Validators.required]]

}, {

validator: ConfirmedValidator('password', 'confirm_password')



get f(){

return this.form.controls;







import { FormGroup } from '@angular/forms';

export function ConfirmedValidator(controlName: string, matchingControlName: string){

return (formGroup: FormGroup) => {

const control = formGroup.controls[controlName];

const matchingControl = formGroup.controls[matchingControlName];

if (matchingControl.errors && !matchingControl.errors.confirmedValidator) {



if (control.value !== matchingControl.value) {

matchingControl.setErrors({ confirmedValidator: true });

} else {





I hope it can help you...

Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: