I have a text material input that is mandatory that says something like "Please enter issue description". However user could just enter spaces or some garbage like xxx and bypass the mandatory check. Is there any npm package or algorithm in Angular 2/typescript that will help me do a real check. Basically some fuzzy logic that will check if at least one meaningful English sentence has been entered. I understand user could enter "Go fly a kite" and bypass but iam really trying to avoid the obvious skips by entering spaces or few words/numbers of garbage. Please advise. Thanks
Asked
Active
Viewed 46 times
1
-
1You could try testing the input with Regex like [here](https://stackoverflow.com/questions/20320719/constructing-regex-pattern-to-match-sentence) – Simon Sheep Oct 22 '18 at 15:19
1 Answers
1
There is a built-in validator with regex support that might help, the pattern validator.
It can be used programmatically:
const control = new FormControl('1', Validators.pattern('[a-zA-Z ]*'));
or it can be used in the template via HTML5's pattern attribute:
<input pattern="[a-zA-Z ]*">

hevans900
- 847
- 7
- 15
-
Plus angular won’t consider a form control as valid if someone just puts spaces in it using Validators.required() – Pari Baker Oct 22 '18 at 20:41