yalpsid eman
yalpsid eman

Reputation: 3452

Validate number with outlying number possibility in class-validator

I have a field in my class that looks like so:

@IsDefined()
@IsInt()
@Min(1)
@Max(10)
someNumber: number;

I'd like someNumber to also be able to be assigned -1. How can I incorporate this without making a custom validator?

Upvotes: 1

Views: 1474

Answers (1)

cyr_x
cyr_x

Reputation: 14257

You could combine the NotEquals with the Min decorator:

@IsDefined()
@IsInt()
@NotEquals(0)
@Min(-1)
@Max(10)
someNumber: number;

Upvotes: 2

Related Questions