joi

Validating nested objects with Joi

北战南征 提交于 2020-08-07 05:30:38
问题 How to validate this object using joi? Im using Joi with Hapi api. { "email":"rambo@gmail.com", "password":"abc123", "active":"", "details": { "firstName": "Rambo", "lastName": "Comando", "phoneNumber": "5554446655", "billing":{ "firstName": "", "lastName": "", "phoneNumber": "", "address": "", "adress2": "", "postalCode": "", "city": "", "state": "", "country": "", "stripeId": "" } } } I tried doing like this, but it is not working. What is the correct way of doing this? payload: { email:

Validating nested objects with Joi

爱⌒轻易说出口 提交于 2020-08-07 05:30:11
问题 How to validate this object using joi? Im using Joi with Hapi api. { "email":"rambo@gmail.com", "password":"abc123", "active":"", "details": { "firstName": "Rambo", "lastName": "Comando", "phoneNumber": "5554446655", "billing":{ "firstName": "", "lastName": "", "phoneNumber": "", "address": "", "adress2": "", "postalCode": "", "city": "", "state": "", "country": "", "stripeId": "" } } } I tried doing like this, but it is not working. What is the correct way of doing this? payload: { email:

Validating nested objects with Joi

馋奶兔 提交于 2020-08-07 05:29:58
问题 How to validate this object using joi? Im using Joi with Hapi api. { "email":"rambo@gmail.com", "password":"abc123", "active":"", "details": { "firstName": "Rambo", "lastName": "Comando", "phoneNumber": "5554446655", "billing":{ "firstName": "", "lastName": "", "phoneNumber": "", "address": "", "adress2": "", "postalCode": "", "city": "", "state": "", "country": "", "stripeId": "" } } } I tried doing like this, but it is not working. What is the correct way of doing this? payload: { email:

Validating nested objects with Joi

|▌冷眼眸甩不掉的悲伤 提交于 2020-08-07 05:29:07
问题 How to validate this object using joi? Im using Joi with Hapi api. { "email":"rambo@gmail.com", "password":"abc123", "active":"", "details": { "firstName": "Rambo", "lastName": "Comando", "phoneNumber": "5554446655", "billing":{ "firstName": "", "lastName": "", "phoneNumber": "", "address": "", "adress2": "", "postalCode": "", "city": "", "state": "", "country": "", "stripeId": "" } } } I tried doing like this, but it is not working. What is the correct way of doing this? payload: { email:

Joi validating time field

折月煮酒 提交于 2020-07-07 04:25:52
问题 There is object with a property time (22:30:00). const schema = Joi.object.keys({ ... transactionDate: Joi.date().required(), transactionTime: Joi.time().required(), // ??? ... }); How to validate a time field using Joi ? 回答1: Try this way const schema = Joi.object().keys({ ... transactionDate: Joi.string().regex(/^([0-9]{2})\:([0-9]{2})$/) }) Hear I have used simple regex format. You can also use this : ^([01]\d|2[0-3]):?([0-5]\d)$ for AM and PM \b((1[0-2]|0?[1-9]):([0-5][0-9])([AaPp][Mm]))

Joi validator only one of keys

大城市里の小女人 提交于 2020-07-06 20:11:58
问题 I am working on an api that should allow multiple params but for three of them I would like to allow only one of them. It easier with values for each key but I am wondering if Joi allows it too or I should add extra validation logic in my server. In short, for keys a , b or c I want to fail any request that has more than one of the three, so: http://myapi.com/?a=value is a valid request. http://myapi.com/?b=value&c=value2 is invalid . Thanks! 回答1: You're looking for object.xor(peers) if

Joi validator only one of keys

大兔子大兔子 提交于 2020-07-06 20:11:17
问题 I am working on an api that should allow multiple params but for three of them I would like to allow only one of them. It easier with values for each key but I am wondering if Joi allows it too or I should add extra validation logic in my server. In short, for keys a , b or c I want to fail any request that has more than one of the three, so: http://myapi.com/?a=value is a valid request. http://myapi.com/?b=value&c=value2 is invalid . Thanks! 回答1: You're looking for object.xor(peers) if

Joi validator only one of keys

别等时光非礼了梦想. 提交于 2020-07-06 20:11:02
问题 I am working on an api that should allow multiple params but for three of them I would like to allow only one of them. It easier with values for each key but I am wondering if Joi allows it too or I should add extra validation logic in my server. In short, for keys a , b or c I want to fail any request that has more than one of the three, so: http://myapi.com/?a=value is a valid request. http://myapi.com/?b=value&c=value2 is invalid . Thanks! 回答1: You're looking for object.xor(peers) if

Joi Regex is not recognized as Regex Pattern

纵然是瞬间 提交于 2020-06-28 02:09:44
问题 I'm trying to make a validation rule for password field that it should consists of the following: Must have a number Must contain at least one upper-case Must contain at least one lower-case Must contain any of the following symbols [@$!] Should be at 8 to 20 characters only. Here's the regex pattern I use: (?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!#.])[A-Za-z\d$@$!%*?&.]{8,20} Tested on https://regexr.com/ Here's the Joi validation: password: Joi.string() .regex( '/(?=.*[a-z])(?=.*[A-Z])(?=.*d