I want to allow users to just adding numbers "12345" and decimal numbers like "21321.12312" and negative numbers like -23423.32432. Users shouldn't be able to add multiple "." like "12..32" and add "-" just in first of input like -324.34 not like 324-4323.
I used this regEx r'^(-?\d+\.\d+)(\s*,\s*-?\d+\.\d+)+$'
but can't enter anything.
TextField code:
TextFormField(
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp(r'^(-?\d+\.\d+)(\s*,\s*-?\d+\.\d+)+$')),
],
controller: budget,
keyboardType: TextInputType.number,
decoration: InputDecoration(
contentPadding:
EdgeInsets.only(right: 20, left: 20, top: 10, bottom: 10),
hintText: getTranslated(context, "budget_example"),
hintStyle: TextStyle(fontSize: 13, fontFamily: "tahoma"),
border: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: MyColors.secondary),
borderRadius: BorderRadius.circular(100),
),
),
),
Allow only 1 .
Allow negative
Place negative sign on beginning
We should create our own input formatter
and (don't forget to import the previous class)