How to implement custom confirm password validator in Angular 2 (Final) (template driven form)
Jecelyn Yeen
882

Hi Jecelyn,

Thank you for an original solution on the equality validation. You are right: there are a lot of different ways to implement validation, including model-driven approach in stack overflow you referred to.

It looks that template-driven approach I propose, is even more simpler. All you have to do is wrap the target passwords with div tag:

<div ngModelGroup #pswGroup=”ngModelGroup” validateEqual>

and place somewhere an element to display error:

<small [hidden]=”!pswGroup.errors” class=”text-danger”>
 Password mismatch
 </small>

The implementation of the validator becomes quite primitive. See my plunk: http://plnkr.co/edit/EUWyRDwLm5vmVi2Y04k8?p=preview

Note, that in this solution the required validation of the confirm password also works!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.