import { FormControl , FormGroup } from '@angular/forms' ; export function matchPasswords ( passwordKey , confirmPasswordKey ) { return ( group ) : { [ key ] : any ; } => { const password = group . controls [ passwordKey ] ; const confirmPassword = group . controls [ confirmPasswordKey ] ; if ( password . value !== confirmPassword . value ) { return { mismatchedPasswords : true } ; } } ; } param { FormControl } formControl returns { { emailValidator : { valid : boolean } } } export function emailValidator ( formControl ) { const EMAIL_REGEX = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ ; return EMAIL_REGEX . test ( formControl . value ) ? null : { emailValidator : { valid : false } } ; }