Created
April 21, 2020 18:04
-
-
Save DejanBelic/0264626374e57d8759cdf4bbf534b65d to your computer and use it in GitHub Desktop.
Angular custom validator - restricted words
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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