As from my previous question I'm trying to allow only numbers in double format into a TextField. I have looked through the whole wide web and didn't find a Regex for dart.
TextFormField(
inputFormatters: [
WhitelistingTextInputFormatter(RegExp(r'\d*\.?\d+')) //<-- useless attempt to allow double digits only
])
Update:
The WhitelistingTextInputFormatter was deprecated after v1.20.0-1.0.pre. So use FilteringTextInputFormatter:
FilteringTextInputFormatter.allow(RegExp(r'(^\d*\.?\d*)'))
Before v1.20.0-1.0.pre:
You can try with:
WhitelistingTextInputFormatter(RegExp(r'(^\d*\.?\d*)'))
And the following is a stricter version of this regex. If the user press any invalid character other than the desired format the field will get cleared.
WhitelistingTextInputFormatter(RegExp(r'(^\d*\.?\d*)$'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With