flutter – Regex for ONLY positive and negative integer in input formatter for a TextFormField
I am trying to have a TextFormField which only accepts negative and positive number of 5 digits.
The following code but it does restrict digits only and up to 5, but it is not accepting a negative sign.
new TextFormField(
maxLines: 1,
keyboardType: TextInputType.number,
enableSuggestions: false,
inputFormatters: [
LengthLimitingTextInputFormatter(5),
FilteringTextInputFormatter.allow(RegExp(r'-?[0-9]')),
],
onChanged: (val) {},
);
I have tried the following regex: “-?[0-9]” but it does not allow the negative sign.
Read more here: Source link
