Fix keyword validator
This commit is contained in:
parent
f5b8ef21a2
commit
653cc82b47
@ -1,6 +1,19 @@
|
||||
import {AbstractControl} from '@angular/forms';
|
||||
|
||||
export function keywordsValidator(control: AbstractControl): { [key: string]: any } | null {
|
||||
const valid = /^((\w){3,},?){1,2}(\w{3,})?$/.test(control.value);
|
||||
return valid ? null : {'invalidKeywords': {value: control.value}};
|
||||
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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user