-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Support plan
- which support plan is this issue covered by? (e.g. Community, Core, Plus, or Enterprise): Community
- is this issue currently blocking your project? (yes/no): yes
- is this issue affecting a production system? (yes/no): no
Context
- node version: v12.16.1
- module version: v16.1.7
- environment (e.g. node, browser, native): node
- used with (e.g. hapi application, another framework, standalone, ...): hapi
- any other relevant information:
How can we help?
Hello,
I want to validate multiple value ranges for single attribute. There are many ranges for single attribute and I need to validate for more than 100 attributes.
Say attribute age can have value range range1 = between 10 to 15.
attribute age can have value range range2 = between 20 to 25.
I want to validate these two rules in such a way that If I pass attribute value 11. The result can let me know yes it is valid because of range1. So when I am using this code
const range1 = Joi.number().integer().min(10).max(15).invalid(7);
const range2 = Joi.number().integer().min(20).max(25).invalid(12)
const schema = Joi.object({
age: Joi.alternatives().try(range2, range1)
})
it gives me just value as a response in case any of the passed value is in between any of the ranges. I want for which range it was successful.
Question 1 - I want error like information for any of the successful validation too OR Is it possible to set custom successful message for validation instead of just value return?
Question 2 - Joi.alternative gives error only in case of all of the passed schema fails. Is there any other way to achieve this error and success both for all schema that are validated. Please help.