Home > front end >  Flutter add dash after every 3 number textfield input and limit number of figure input
Flutter add dash after every 3 number textfield input and limit number of figure input

Time:03-02

I'm looking for a way to add ( - ) after every number input in flutter textformfield and to limit the number of input to just 9 figure. For example 145-123-234. I will appreciate if anyone can help with this.

CodePudding user response:

us input formatters:

inputFormatters: [ FilteringTextInputFormatter.allow(RegExp('[0-9,-]')), LengthLimitingTextInputFormatter(9), ],

this may help you number of input digits will work fine and regex expression for dash after 3 will change in your case in your case may change.

CodePudding user response:

You can use mask text formatter package sample usage:

 var maskFormatter = new MaskTextInputFormatter(
      mask: ' # (###) ###-##-##', filter: {"#": RegExp(r'[0-9]')});
      
   TextField(
                      inputFormatters: [ maskFormatter],
                      autoFocus: false,
                      inputType: TextInputType.phone,
                      inputAction: TextInputAction.done,
                      },
                    ),

  • Related