import {AbstractControl} from '@angular/forms'; export function keywordsValidator(control: AbstractControl): { [key: string]: any } | null { if (control.value === null) { return null; } let split: string[]; split = control.value.split(','); if (split.length > 3) { return {'invalidKeywords': {value: control.value}}; } for (let i = 0; i < split.length; i++) { const word = split[i].trim(); if (word.length < 3) { return {'invalidKeywords': {value: control.value}}; } } return null; }