Venkatesh
Venkatesh

Reputation: 200

When I use "FilteringTextInputFormatter.allow" itremoves the entire value of TextFormField

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

Answers (1)

Morteza Mohammadi
Morteza Mohammadi

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

Related Questions