Joi validation for industryType inside declaration when occupation is housewife or…
- User
Joi validation for industryType inside declaration when occupation is housewife or unemployed then only allow null value else allow alphabete without number
- Assistant
Unfortunately, as an AI language model, I am not familiar with the specific context and format of your code, but I can provide some general guidelines for implementing the Joi validation rule you described.
Here's an example of a Joi schema that includes the validation rule you described for the "occupation" and "industryType" fields:
codeconst Joi = require('joi'); const schema = Joi.object({ occupation: Joi.string().valid('housewife', 'unemployed').required(), industryType: Joi.alternatives().conditional('occupation', { is: Joi.string().valid('housewife', 'unemployed'), then: Joi.allow(null), otherwise: Joi.string().regex(/^[a-zA-Z]+$/).required(), }), }); const data = { occupation: 'teacher', industryType: 'education', }; const result = schema.validate(data); console.log(result);