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) {
  if (value != null) {
    final endWithText = useTrim ? endWith.trim() : endWith;
    final text = useTrim ? value.trim() : value;
    if (!caseSensitive) {
      if (!text.toLowerCase().endsWith(endWithText.toLowerCase())) {
        return getErrorMessage(
          EasyValidatorMessages.instance.endWith,
          endWith,
        );
      }
    } else {
      if (!text.endsWith(endWithText)) {
        return getErrorMessage(
          EasyValidatorMessages.instance.endWith,
          endWith,
        );
      }
    }
  }
  return null;
}