Skip to content

Instantly share code, notes, and snippets.

@onwuvic
Created August 12, 2020 06:35
Show Gist options
  • Save onwuvic/d378bf0e2de1cfabdb52e4941b628044 to your computer and use it in GitHub Desktop.
Save onwuvic/d378bf0e2de1cfabdb52e4941b628044 to your computer and use it in GitHub Desktop.
import { AbstractControl } from '@angular/forms';
export class PasswordMatcher {
static match(control: AbstractControl): void | null {
const passwordControl = control.get('password');
const confirmPasswordControl = control.get('confirmPassword');
if (passwordControl.pristine || confirmPasswordControl.pristine) {
return null;
}
if (passwordControl.value === confirmPasswordControl.value) {
return null;
}
confirmPasswordControl.setErrors({ match: true });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment