Skip to main content
Version: 1.5.0

Multiple Types

If you provide an array of types (e.g., ['string', 'number']), the value will be considered valid if it matches any one of the specified types.

Example

Request Body

{
"user": {
"profile": {
"name": "John Doe",
"age": 30
}
}
}

Validation Rules

const rules = [
{
key: "user.profile.age",
type: ["string", "number"],
required: true,
min: 18,
max: 100,
}
];

  • key: "user.profile.age" specifies the field in the request body to be validated.

  • type: ["string", "number"] indicates that the value can be either a string or a number. The validation will succeed if the value matches any one of these types.

  • required: true means that the user.profile.age property must be present in the request body.

  • min: 18 specifies that the minimum allowed value for the age should be 18. This applies if the value is of type number.

  • max: 100 specifies that the maximum allowed value for the age should be 100. This applies if the value is of type number.