validate method

  1. @override
String? validate(
  1. String? value
)
override

Validates the given value and returns an error message if the value is invalid.

Implementation

@override
String? validate(String? value) {
  assert(maxWordCount > 0, 'The maximum words count must be greater than 0');
  if (value != null && value.isNotEmpty) {
    final words = value.trim().split(' ');
    if (words.length > maxWordCount) {
      return getErrorMessage(
        EasyValidatorMessages.instance.maxWordCount,
        maxWordCount.toString(),
      );
    }
  }
  return null;
}