Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

joi string custom validation fuction

const customValidator = (value, helpers) => {
  if (!isAddress(value)) {
    return helpers.message("Invalid address");
  } else {
    return value;
  }
};

const createSchema = Joi.object({
  address: Joi.string()
    .required()
    .custom((value, helper) => customValidator(value, helper)),
  key: Joi.string().required(),
  index: Joi.string().required(),
});
 
PREVIOUS NEXT
Tagged: #joi #string #custom #validation #fuction
ADD COMMENT
Topic
Name
9+4 =