How to deny the point just at the beginning of the textfield Flutter

118 views Asked by At

I have a problem with my textfield, I set it allowing only numbers and banning the comma, minus and space that I didn't need. But now I have a problem with the point because I don't want to ban it completely but remove the possibility of putting it as the first digit, leaving the availability to use it after a number. And then if it were possible I would also like to put the limit of being able to write it once. Here is my code:

inputFormatters: [FilteringTextInputFormatter.deny(RegExp('[-, ]'))],

Searching online I found an answer in which he explained that to allow less only at the beginning it was enough to use this:

inputFormatter: FilteringTextInputFormatter.allow(new RegExp("^-?\\d*")),

I tried replacing - with . and allow with deny but it didn't work.

(This is what I got: inputFormatter: FilteringTextInputFormatter.deny(new RegExp("^.?\\d*")))

1

There are 1 answers

0
powerman23rus On

You can use this regexp to allow you use digits with point inside

^\d+(\.\d+)?$

Sandbox with regex