Gullu
Gullu

Reputation: 3529

angular 2 text input make meaningful mandatory

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

Upvotes: 1

Views: 51

Answers (1)

hevans900
hevans900

Reputation: 897

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 ]*">

Upvotes: 1

Related Questions