import { AbstractControl , ValidatorFn } from '@angular/forms' ; export function UniqueValidator ( uniqueList ) { return ( control ) : { [ key ] : any ; } | null => { if ( uniqueList . indexOf ( control . value ) !== - 1 ) { return { nonUnique : { value : control . value , } , } ; } } ; } export function ListValidator ( allowList ) { return ( control ) : { [ key ] : any ; } | null => { if ( allowList . indexOf ( control . value ) === - 1 ) { return { notInList : { value : control . value , } , } ; } } ; } export function validateDate ( control ) { if ( ! /^\d{4}-\d{2}-\d{2}$/ . test ( control . value ) ) { return { invalid : { value : control . value , } , } ; } }