Home > Back-end >  i want negative and postive value two number after decimal in texinput format
i want negative and postive value two number after decimal in texinput format

Time:09-28

  FilteringTextInputFormatter.allow(
                            RegExp(r'^\d \.?\d{0,2}')),

this flitering texinput only allow number and decimal value (eg,1.22) but i want (-1.22)

FilteringTextInputFormatter.allow(RegExp(r"[-0-9]")),

but this allow negative and postive value but i cannot deny decimaly more than two value after the point

CodePudding user response:

You can add escaped "-" in front

RegExp(r'^\-\d \.?\d{0,2}')

And if you want to match negative and positive numbers use

RegExp(r'^\-?\d \.?\d{0,2}')

? will make regex match between 0 or 1 occurrence of "-"

CodePudding user response:

Just add -* like this :

RegExp(r'^\-*\d \.?\d{0,2}')

You can take a reference from here GFG RegExp

  • Related