class-validator icon indicating copy to clipboard operation
class-validator copied to clipboard

@IsOptional cannot work with @MinLength()

Open nikdale opened this issue 7 years ago • 3 comments

Hello, I've tried using this too together but it's not pssoible.

@IsOptional()
@MinLength(3)
comment: string;

So, the ide was to MinLength work only if comment is present. If it's not present the length should not be important. It gives "must be at least 3 chars long error"

nikdale avatar Apr 23 '19 10:04 nikdale

Hy @nikdale I tested this and I am sure you are passing empty string into comment property. As described here https://github.com/typestack/class-validator/pull/110 @IsOptional will omit only undefined and null values. Empty string will pass and @MinLength(3) will throw error.

vlapo avatar Jun 13 '19 22:06 vlapo

Unfortunately, no. I'm not sending anything. I'm checking that currently on req. Thanks anyway! It can be closed for now.

nikdale avatar Jun 17 '19 08:06 nikdale

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jun 24 '19 16:06 lock[bot]