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) {
    String notStartWithText = useTrim ? notStartWith.trim() : notStartWith;
    String text = useTrim ? value.trim() : value;
    if (!caseSensitive) {
      if (text.toLowerCase().startsWith(notStartWithText.toLowerCase())) {
        return getErrorMessage(
          EasyValidatorMessages.instance.notStartWith,
          notStartWith,
        );
      }
    } else {
      if (text.startsWith(notStartWithText)) {
        return getErrorMessage(
          EasyValidatorMessages.instance.notStartWith,
          notStartWith,
        );
      }
    }
  }

  return null;
}