reactive_forms
reactive_forms copied to clipboard
Validators.number works only with integers
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
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
Don't forget you might need the correct keyboard type:
keyboardType: TextInputType.numberWithOptions(signed: true, decimal: true)
any updated?