Reputation: 200
I am using the below code to allow only alphanumeric and some special characters in TextFormField, but when the user types any other characters the entire TextFormField is cleared how to avoid clearing entire user input
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp(r'^[a-zA-Z0-9@_]+$'))
],
Upvotes: 2
Views: 1014
Reputation: 440
Use this code:
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp(r'^[a-zA-Z0-9@_]+'))
],
The Dollar sign ($) at the end is causing the problem.
Upvotes: 5