minWords static method

String? minWords(
  1. String? value,
  2. int min, {
  3. String? fieldName,
})

Validates minimum word count.

Implementation

static String? minWords(String? value, int min, {String? fieldName}) {
  if (value == null || value.isEmpty) {
    return null;
  }

  final wordCount = _countWords(value);
  if (wordCount < min) {
    return '${fieldName ?? "This field"} must contain at least $min words.';
  }

  return null;
}