reactive_forms
reactive_forms copied to clipboard
distinguish validation for number (num) and integer (int)
Actually the Validator.number
is validating integer values:
/// Gets a validator that validates if the control's value is a numeric value.
static Validator<dynamic> get number => const NumberValidator();
...
/// Validator that validates if control's value is a numeric value.
class NumberValidator extends Validator<dynamic> {
/// The regex expression of a numeric string value.
static final RegExp numberRegex = RegExp(r'^-?[0-9]+$');
const NumberValidator() : super();
@override
Map<String, dynamic>? validate(AbstractControl<dynamic> control) {
return (control.value == null) ||
!numberRegex.hasMatch(control.value.toString())
? <String, dynamic>{ValidationMessage.number: true}
: null;
}
}
could it be possible to validate numeric values accepting floating values and then have a Validator.integer
for integer values?