I need to allow only one comma to be added to my inputNumber
in flutter, I can't find any solution for this, can anyone help me with this?
Asked
Active
Viewed 943 times
2

Luan Martins Gepfrie
- 461
- 3
- 10
-
Would love to help, but what exactly do you need? Its not very clear... Do you want to allow only one decimal character after the comma (like 5.4 and not 5.46)? – DoobieAsDave Jul 26 '19 at 15:04
-
I need to block the insertion of more than one comma so that doesn't happen (2,,,30) – Luan Martins Gepfrie Jul 26 '19 at 17:29
-
duplicate of https://stackoverflow.com/questions/56390839/flutter-regex-in-textformfield – Antonin GAVREL Jul 07 '20 at 19:36
-
Does this answer your question? [Flutter - Regex in TextFormField](https://stackoverflow.com/questions/56390839/flutter-regex-in-textformfield) – Antonin GAVREL Jul 07 '20 at 19:36
2 Answers
0
You can White list some text using this:--
WhitelistingTextInputFormatter(RegExp("[a-zA-Z]"))
You can Black list some text using this:--
BlacklistingTextInputFormatter(RegExp("[/\\]"))

Bharat
- 51
- 1
- 7
-
I need to block the insertion of more than one comma so that doesn't happen (2,,,30) – Luan Martins Gepfrie Jul 26 '19 at 19:54
0
A solution I found was to check the digit entered, if it already exists (",") I block it
if ((newChar.contains(",") || newChar.contains(".")) && (oldValue.text.contains(","))) {
return TextEditingValue(
text: oldValue.text,
selection: TextSelection.collapsed(offset: oldValue.text.length),
);
}

Luan Martins Gepfrie
- 461
- 3
- 10