Questions tagged [joi]

Revolutionizing JavaScript Objects: Unveiling an Innovative Schema Description Language and Validator.

Validate input strings in Node.js using Joi to detect and return an error if there are leading or trailing spaces

Looking to set up JOI validation in Node.js that flags errors if a string begins or ends with an empty space. For example: name = "test123" //valid name = "test(space)" or "(space)test" // invalid ...

What is the best way to verify a password's strength with Joi so that it includes 2 numbers, 2 special characters, 2 uppercase letters, and 2 lowercase letters?

Is there a way to achieve this using Joi? For instance: Joi.string() .required() .min(8) .max(16) .pattern(/(?=(?:.*[a-z]){2,16}).+/) .pattern(/(?=(?:.*[A-Z]){2,16}).+/) .pattern(/(?=(?:.*[0-9]){2,16}).+/) .pa ...

Steps for implementing .OR in joi validation

Currently, I am facing an issue with the Joi object in my code. I am attempting to use the Or method but it seems to be failing due to having two objects that contain the phone property. body: Joi.object().keys({ member: Joi.object().required( ...

Removing unexpected keys during validation using Joi

Within my server-side JavaScript code, I am utilizing Joi for validating a JavaScript object. The schema being used is structured as follows: var schema = Joi.object().keys({ displayName: Joi.string().required(), email: Joi.string().email(), e ...

Customize your Joi message using the .or() method

I'm attempting to personalize a message for the .or() function in Joi, similar to this: https://i.stack.imgur.com/68dKx.png The default message from Joi is as follows: Validation Error: "value" must contain at least one of [optionOne, optionTwo] I wou ...

Is there a way to merge two typed Joi schemas together?

I have two different interfaces, where the second one is an extension of the first: interface Core { id: string; } interface User extends Core { firstName: string; } To ensure validation, I utilize Joi schemas. For the Core interface, it's easy to p ...

Node.js/Hapijs - Verify every property and value in JSON object payload without explicitly naming the properties

One of the challenges I'm facing with my API is handling POST-sent payload input that needs to be passed on to another application for processing. The input is always in JSON format, and the values must strictly be numeric. With hundreds of different varia ...

Converting types to "any" and encountering the error message "There are two distinct types with the same name, but they are not related."

I am encountering some challenges while trying to use an NPM module that I developed along with its Typescript typings in another application. To simplify the examples, I will omit properties that are not relevant to the issue at hand. Within my module&ap ...

Troubleshooting the Non-functioning req.value & ip with Node.js - Joi schema

I have implemented a joi schema to validate email and password that are sent as JSON in the request body. Now, I want to add an additional validation for the IP address. However, when I tried to do so, I encountered the following error: { "isJoi": tru ...

Unexpected behavior in Joi-Browser causing issues with React.js form validation

In my quest to create a multi-step form with React.js and material UI, I encountered an issue with Joi-Browser validation. The error message states: ValidationError: "value" must be an object. Since I am new to React.js, I would appreciate any guidance on ...

The variable isJoi has been set to true but there is an error due to an unexpected

I am currently developing a NestJs backend on multiple machines. One of the machines is experiencing issues with the @hapi/joi package. When running the NestJs application in development mode on this specific machine, I encounter the following error: PS C ...

Guide to define maximum image size in Joi or Hapi

Currently, I am facing an issue with nodejs+mongodb. When uploading images on the front-end, the system restricts it to a maximum size of 50kb. However, I would like to increase this limit to 5MB so that larger images (around 1MB or 2MB) can also be upload ...

Validation of a Joi field based on a specific list of options in another field

I need to validate a field within an object based on specific values in another field. Let's say I have two fields, field1 and field2. The possible values for field1 are A, B, C, D, E, F, H, I. If field1 has the value of A, B, or C, then field2 should be n ...

Is it possible to specify an integer property as int64 within a Joi model that is utilized by Hapi Swagger?

I'm currently working with a Joi model that looks like this: const SimpleModel = Joi.object({ id: Joi.number().integer().required().description('ID') }).label('SimpleModel'); This model is being utilized in the following route within @hapi/hapi: { ...

Logging validation errors from Joi in the frontend

I am currently working on a registration form that requires validation using Joi. While I have been able to successfully reflect errors in JSON format, I am facing difficulty in displaying these errors on the frontend. Previously, with express-validator, I ...

Ensuring validity using dynamic context objects within Joi

I need to implement a dynamic validation system that involves downloading an object at runtime and saving it as a well-formed .json file. The objective is to use the values from this downloaded object as part of a validation process using Joi.validate wi ...

Steps to stop Multer File Upload when input validation doesn't pass

Currently, I am in the process of creating a route that handles file uploads (POST) and also stores additional properties to MongoDB along with the file path. The issue I am facing is that even if input validation fails, the file still gets uploaded to the ...

The JOI validation process is failing to return all error messages, even though the "abort early" option

I have been encountering an issue while trying to validate my payload using a joi schema. Instead of returning the errors specified in the schema, only one error is being displayed. Even when I provide a payload with name as "int", it only shows one custom ...

Joi has decided against incorporating custom operators into their extended features

I am having trouble extending the joi class with custom operators. My goal is to validate MongoDB Ids, but when I try to use the extended object, I encounter the following error: error: uncaughtException: JoiObj.string(...).objectId is not a function TypeE ...

Schema-based validation by Joi is recommended for this scenario

How can we apply Joi validation to the schema shown below? What is the process for validating nested objects and arrays in this context? const user = { address: { contactName: 'Sunny', detailAddress: { line1: 'Sector: ...

What's the best way to implement a validation check in Joi to ensure that the new password is not the same as the

Currently, I am in the process of creating Apis utilizing NodeJS and ExpressJS with Joi for schema validation. In one instance, I have a resetUserPinCode controller where I need to ensure that the oldPinCode and newPinCode values are not identical: const r ...

What is the best way to enforce constraints on three keys when validating an object using Joi?

Currently experimenting with Joi for object validation. Able to validate objects with constraints on two keys using any.when(). Now looking to implement validation with constraints on three keys, for example: var object = { dynamicPrize: false, ...

Ensuring Array Values in Mongoose Schema are Validated and Defined

Just entering the world of mongoose and looking to validate an array with specific predefined values like enum. Check out my schema below: const movieSchema = new mongoose.Schema({ language:{ type:[String], enum : ['Hindi','English','Gujarati',' ...

What is the best way to integrate joi-password-complexity into Joi validation?

I am looking to strengthen password security during user registration by utilizing the joi-password-complexity package. https://github.com/kamronbatman/joi-password-complexity However, I encountered an error when attempting to implement it: (node:1487 ...

Intentionally introduce discrepancies in the errors during validation of an object using hapi/joi

const validationSchema = Joi.object().keys({ Id: Joi.number().required(), CustomerName: Joi.string() .trim() .required() .when('$isInValidCustomer', { is: true, ...

Is there a way to determine whether all fields in a schema have been populated or remain empty?

I am working with a schema that looks like this: How can I determine if all the fields in the schema have been filled or not? The front-end (React.js) includes an onboarding process where users who are logging in for the first time need to complete onboa ...