0

how can I validate password and confirm password is must same otherwise not submit .

<div class="col-md-6 col-md-offset-3">
    <h2>Change Password</h2>
    <form name="form1" (ngSubmit)="f.form.valid && cpass()" #f="ngForm" novalidate>
        <div class="form-group" [ngClass]="{ 'has-error': f.submitted && !password.valid }">
            <label for="password">Password</label>
            <input type="password" class="form-control" name="password" [(ngModel)]="model.password" #password="ngModel" required />
            <div *ngIf="f.submitted && !password.valid" class="help-block">Password is required</div>
        </div>
        <div class="form-group" [ngClass]="{ 'has-error': f.submitted && !confirm-password.valid }">
            <label for="confirm-password">Confirm Password</label>
            <input type="password" class="form-control" name="confirm-password" [(ngModel)]="model.confirm-password" #password="ngModel" required />
            <div *ngIf="f.submitted && !confirm-password.valid" class="help-block">Password is required</div>
        </div>
        <div class="form-group">
            <button class="btn btn-primary">Save</button>
            <a [routerLink]="['/home']" class="btn btn-link">Cancel</a>
        </div>
    </form>
</div>
Krunal
  • 938
  • 2
  • 10
  • 33
  • possible duplicate https://stackoverflow.com/questions/44449673/angular-4-custom-validator-on-reactive-form-for-password-and-confirm-password-m/44449802#44449802 – Shailesh Ladumor Jun 20 '17 at 13:12
  • just add at your input tag pattern="^[a-zA-Z0–9_.+-]+@[a-zA-Z0–9-]+.[a-zA-Z0–9-.]+$" (just with password validation) – Yoav Schniederman Jun 20 '17 at 13:12
  • after click on save button I want to remove text/password from the input box , any solution please ?? @ Yoav Schniederman – Krunal Jun 21 '17 at 06:17

1 Answers1

0

You need to implement a custom validator to do something like confirm password

Here's a good article on this subject

https://scotch.io/tutorials/how-to-implement-a-custom-validator-directive-confirm-password-in-angular-2

Dean Chalk
  • 20,076
  • 6
  • 59
  • 90