Home > other >  Flutter RegularExpression to avoid special characters
Flutter RegularExpression to avoid special characters

Time:09-29

Flutter RegularExpression to avoid special characters in textfield and to allow only numbers, alphabet and japanese letters. How to achieve this?

Sample input :"abc123英語"

CodePudding user response:

Add this to your TextField for letters and numbers

inputFormatters: [new  WhitelistingTextInputFormatter(RegExp("[a-zA-Z0-9]")),],

Add a BlacklistingTextInputFormatter to your TextField

 inputFormatters: [
    new BlacklistingTextInputFormatter(new RegExp('[\\.]')),
  ],

CodePudding user response:

Try this one:

RegExp("/[一-龠] |[ぁ-ゔ] |[ァ-ヴー] |[a-zA-Z0-9] |[a-zA-Z0-9] |[々〆〤ヶ] /u")
  • Related