Seeking assistance on validating the number of digits for numeric values using class-validator
. Specifically, I want my entity to only accept numbers with 6 digits for a certain property. For example:
const user1 = new User();
user1.code = 123456 // should be valid
const user2 = new User();
user2.code = 12345 // should be invalid
const user3 = new User();
user3.code = 1234567 // should be invalid
I attempted to use IsNumber, MinLength, and MaxLength together, but it didn't work as expected.
class User {
@IsPositive()
@IsNotEmpty()
@IsNumber({ maxDecimalPlaces: 0 })
@MinLength(6)
@MaxLength(6)
public code: number;
}
Getting an error message stating that
code must be shorter than or equal to 6 characters
.
If anyone has any guidance, I would greatly appreciate it!