Reputation: 809
I am using basic input
component for validating name
.
It is accepting only characters and not allowing any special characters to enter. This condition is working fine.
Validating code:
firstname: [null, [Validators.required, Validators.pattern('[a-zA-Z][a-zA-Z]+')]],
But i need one more requirement:
1) It should accept even a single character, but it is accepting minimum 2 character by default.How can i change this default behaviour??
Here is the stackblitz link.
Upvotes: 0
Views: 386
Reputation: 116
Problem is with the regular expression you have written in Validators.pattern(), it looks for 2 characters minimum, remove on [a-zA-z] block and it should work fine as you desire.
Upvotes: 2
Reputation: 118
Try reduce regex pattern to [a-zA-Z]+
It will take from 1 to unlimited amount of characters. Yor current regex takes char then unlimited amount of characters so it need minimal two characters to match.
Upvotes: 1