Issue
I am trying to validate input type="text"
using a pattern. I want text only.
Component :
this.from = this.fb.group({
name: ['',[Validators.required,Validators.pattern('/^[a-zA-Z]+$/')]],
});
Html :
<input type="text" formControlName="name"/> // omitting other html template like from tag.
The above pattern validation is not working for me. It always returns an invalid state.
Solution
Pass pattern as string, without /
which are the delimiters for regex
Validators.pattern('^[a-zA-Z]+$')
Answered By - Günter Zöchbauer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.