20 lines
533 B
TypeScript
20 lines
533 B
TypeScript
import {AbstractControl} from '@angular/forms';
|
|
|
|
export function keywordsValidator(control: AbstractControl): { [key: string]: any } | null {
|
|
if (control.value == undefined) {
|
|
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;
|
|
}
|