How to prevent entering numbers in Flutter TextFormField?

Viewed 38

I am developing an application with Flutter. I put TextFormField. I want to prevent entering numbers in this TextFormField. How can I do that?

3 Answers

You can use the validator argument to create a callback if the user input a number. You can also add the keyboardType argument to limit the user to only text with the value TextInputType.text

   inputFormatters: [
                      FilteringTextInputFormatter.deny(RegExp("[0-9]")),
                    ],

You need to add this

Try this:

TextFormField(
 inputFormatters: <TextInputFormatter>[
      FilteringTextInputFormatter.deny(RegExp('[0-9]')),
  ], 
),
Related