I have developed my own validation class as a learning exercise. Do you think this is an effective approach, or do you have suggestions for improvement?
import { AbstractControl } from '@angular/forms';
export class ProjectNameValidator {
private static blackList = ['Test1'];
static validateName(control: AbstractControl): {[key: string]: boolean} | null {
const name: string = control.value;
let isValid = true;
ProjectNameValidator.blackList.forEach(forbiddenName => {
if (forbiddenName === name) {
isValid = !isValid;
}
});
return isValid ? null : {'Forbidden name': true};
}
}