import { ValidatorFn , AbstractControl } from '@angular/forms' ; export const patternValidator = ( pattern ) : ValidatorFn => { return ( control ) : { [ key ] : any ; } => { const valid = new RegExp ( pattern ) . test ( control . value ) ; return valid ? null : { patternNotMatching : { value : control . value } } ; } ; } ;