validate method

  1. @override
void validate(
  1. String? newValue
)
override

Implementation

@override
void validate(String? newValue) {
  final String? valueLocal = newValue;

  if (valueLocal == null) {
    if (isRequired) {
      throw RequiredValueException();
    } else {
      return;
    }
  }

  final int? maxLenghtLocal = maxLenght;
  final int? minLenghtLocal = minLenght;

  if (maxLenghtLocal == null && minLenghtLocal == null) {
    return;
  }

  if (maxLenghtLocal != null) {
    if (valueLocal.length > maxLenghtLocal) {
      throw TooLongValueException();
    }
  }

  if (minLenghtLocal != null) {
    if (valueLocal.length < minLenghtLocal) {
      throw TooShortValueException();
    }
  }
}