Search code examples
regexflutterdartinputformatter

InputFormatter should allow negative and decimal numbers


I want to allow users to just adding numbers like 123456.78912445, -12345.7777777899, 1234567, -12345678. There is no number limit. How can i write Regrex pattern for this textformfield. Same Question inputFormatter should allow just decimal numbers and negative numbers

TextFormField(inputFormatters:[FilteringTextInputFormatter.allow(RegExp())])

Solution

  • Try this: ^\-*\d+(?:.\d+)?$

    And example: https://regex101.com/r/yQDyoM/1