maxLength function

String maxLength (
  1. String fieldValue,
  2. int maxLen,
  3. {String message}
)

Validates that the string fieldValue is not longer than maxLen.

Returns null if fieldValue.length() <= maxLen else an error message

Implementation

String maxLength(
  String fieldValue,
  int maxLen, {
  String message,
}) {
  if ((fieldValue == null) || (fieldValue.length <= maxLen)) {
    return null;
  }
  return message ?? 'Please enter not more than $maxLen characters';
}