Skip to content

Instantly share code, notes, and snippets.

@DejanBelic
Created April 21, 2020 18:04
Show Gist options
  • Save DejanBelic/0264626374e57d8759cdf4bbf534b65d to your computer and use it in GitHub Desktop.
Save DejanBelic/0264626374e57d8759cdf4bbf534b65d to your computer and use it in GitHub Desktop.
Angular custom validator - restricted words
private restrictedWords(words) {
return (control: FormControl): {[key: string]: any} => {
if (!words ) { return null; }
const invalidWords = words
.map(word => control.value.includes(word) ? word : null)
.filter(word => word != null);
return invalidWords && invalidWords.length > 0
? { restrictedWords: invalidWords.join(', ')}
: null;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment