I'm trying to get dart to validate a float that my user will enter in my form. I took the guidance from this SO thread (Regular expression for floating point numbers) on Regex expressions for floating point numbers (for eg, 12.830), and tried it in my flutter app.
new TextFormField(
controller: amt_invested,
keyboardType: TextInputType.number,
inputFormatters: [WhitelistingTextInputFormatter(new RegExp(r'[+-]?([0-9]*[.])?[0-9]+'))],
decoration: const InputDecoration(
filled: true,
fillColor: CupertinoColors.white,
border: const OutlineInputBorder(),
labelText: 'Amount invested',
prefixText: '\R',
suffixText: 'ZAR',
suffixStyle:
const TextStyle(color: Colors.green)),
maxLines: 1,
validator: (val) => val.isEmpty ? 'Amount is required' : null,
),
However, the regex is preventing me from entering the full-stop in the float, contrary to what the SO thread said. How do I get this to work properly?