Reputation: 71
I want a text form field which will accept only alphabets not digits and special characters. If the user clicks on special character also that character on click in key board type should not work.
Upvotes: 0
Views: 1679
Reputation: 1428
Adding a inputFormatter will work.
To allow space between
inputFormatter: [
FilteringTextInputFormatter.allow(RegExp("[a-zA-Z ]")),
],
No space between
inputFormatter: [
FilteringTextInputFormatter.allow(RegExp("[a-zA-Z]")),
],
Digits only
inputFormatter: [
FilteringTextInputFormatter.digitsOnly,
],
Upvotes: 3
Reputation: 77
You can add inputFormatters property to your TextField widget like this:
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.allow(RegExp("[a-zA-Z]")),
],
Upvotes: 1