I need to conditional validate an input filed in nestjs, class-validator. There is a validateif decorator but how to add another validation in else section? For example: if first input was email use email decorator if it was phone match my regex.
@IsNotEmpty()
@IsEnum(UsernameType)
public type: UsernameType;
// enum has two value: phone and email
@IsNotEmpty()
@ValidateIf(o => o.type === UsernameType.PHONE )
@Matches(/(09)[0-9]{9}/)
username: number;
@IsNotEmpty()
@ValidateIf(o => o.type === UsernameType.EMAIL)
@IsEmail()
username: string;