reactive_forms icon indicating copy to clipboard operation
reactive_forms copied to clipboard

Validators.number works only with integers

Open claudiodriussi opened this issue 3 years ago • 3 comments

To validate double I wrote my own validator:

Map<String, dynamic>? floatNumber(AbstractControl<dynamic> control) {
  final RegExp numberRegex = RegExp(r'[+-]?([0-9]*[.])?[0-9]+$');
  if (control.isNull || !numberRegex.hasMatch(control.value.toString())) {
    return {'Invalid number': true};
  }
  return null;
}

It would be useful to add the floatnumber validator to the default validators.

Best regards

claudiodriussi avatar Oct 02 '21 10:10 claudiodriussi

Hi @claudiodriussi,

You are completed right about it. We need a Float Number validator. THanks for the example code. I will add it as feature to include it in futures releases.

Thanks

joanpablo avatar Oct 12 '21 08:10 joanpablo

Don't forget you might need the correct keyboard type:

keyboardType: TextInputType.numberWithOptions(signed: true, decimal: true)

jeremylcarter avatar Nov 09 '21 22:11 jeremylcarter

any updated?

or-nayax avatar Sep 12 '22 12:09 or-nayax