Only one or two digits number before the decimal point in texfFormField flutter. And User can't add more than three digits after the decimal point.
Asked
Active
Viewed 451 times
2 Answers
0
If your String what the user typed is called value
:
List<String> split = value.split('.');
if (split.elementAt(0).length > 2 || split.elementAt(1).length > 3) print('Not valid');
If you need something more advanced: How to allow only 2 digits and 1 digit after the comma (.)?

stacktrace2234
- 1,172
- 1
- 12
- 22
0
you can use RegExp class
final isValidNumber = RegExp(r'^([0-9]{2})*\.[0-9]{2}$');
if (!isValidNumber .hasMatch(number))
numbererror = "Please Enter Valid Name";
else
numbererror = "";

bhagavati antala
- 159
- 5