I’m using RegExp for positive decimal numbers
TextFormField(
keyboardType: TextInputType.numberWithOptions(decimal: true),
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp(r'^\s*(?=.*[1-9])\d*(?:\.\d{1,2})?\s*$')),
],
)
But when I enter something like 1.x, the TextFormField deletes the entire input. What am I doing wrong?
>Solution :
the issue is that your regular expression don’t give you the ability to have a . without a digit after it. you can copy past x.y but you can’t type it one char at a time.
the solution would be relative to what you want and prioritize, but I think this regex might solve the issue :
r'^\s*(?=.*[1-9])\d?\.*(?:\d{1,2})?\s*$'