stringIsOfLength function

Validator stringIsOfLength(
  1. int size
)

Validates that the String's length is the same as the provided size

This validator also validates that the value is a String first So there's no need to add the isTypeString validator when using this validator

Implementation

Validator stringIsOfLength(int size) {
  return (value) {
    final isStringResult = isType<String>().call(value);
    if (isStringResult.isNotValid) return isStringResult;

    return Result(
      isValid: (value as String).length == size,
      expected: 'String of length $size',
      value: value,
    );
  };
}