maxWords static method

String? maxWords(
  1. String? value,
  2. int max, {
  3. String? fieldName,
})

Validates maximum word count.

Implementation

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

  final wordCount = _countWords(value);
  if (wordCount > max) {
    return '${fieldName ?? "This field"} must not exceed $max words.';
  }

  return null;
}