I want to have a regular expression in flutter on my TextFormField, that only numbers between -999 & 999 can be put in. When I tested the expression everything worked how I wanted to, but I don't know why I can not write "-" in the TextFormField. The maximum numbers and that a number should not start with 0 works perfectly fine, but all the time I try to add a minus it doesn't work. I would be thankful for any help!
TextFormField(
decoration: kTextFieldDecoration,
style: kCustomNumberBoxTextStyle,
keyboardType: TextInputType.numberWithOptions(signed: true),
textAlign: TextAlign.center,
initialValue: number.toString(),
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp(r'^-?[1-9]([0-9]{1,2})?')),
],
onChanged: (String newValue) {
if (newValue != "") {
setState(() {
number = int.parse(newValue);
});
widget.onTap(int.parse(newValue));
}
},
),