|
21 | 21 | - [npm note](#npm-note)
|
22 | 22 | - [Examples](#examples)
|
23 | 23 | - [`any`](#any)
|
| 24 | + - [`any.validate(value, [options], [callback])`](#anyvalidatevalue-options-callback) |
24 | 25 | - [`any.allow(value)`](#anyallowvalue)
|
25 | 26 | - [`any.valid(value)` - aliases: `only`, `equal`](#anyvalidvalue---aliases-only-equal)
|
26 | 27 | - [`any.invalid(value)` - aliases: `disallow`, `not`](#anyinvalidvalue---aliases-disallow-not)
|
@@ -392,6 +393,32 @@ const any = Joi.any();
|
392 | 393 | any.validate('a', (err, value) => { });
|
393 | 394 | ```
|
394 | 395 |
|
| 396 | +#### `any.validate(value, [options], [callback])` |
| 397 | + |
| 398 | +Validates a value using the schema and options where: |
| 399 | +- `value` - the value being validated. |
| 400 | +- `options` - an object with the same optional keys as [`Joi.validate(value, schema, options, callback)`](#validatevalue-schema-options-callback). |
| 401 | +- `callback` - an optional synchronous callback method using the the same signature as [`Joi.validate(value, schema, options, callback)`](#validatevalue-schema-options-callback). |
| 402 | + |
| 403 | +```js |
| 404 | +const schema = Joi.object({ |
| 405 | + a: Joi.number() |
| 406 | +}); |
| 407 | + |
| 408 | +const value = { |
| 409 | + a: '123' |
| 410 | +}; |
| 411 | + |
| 412 | +schema.validate(value, (err, value) => { }); |
| 413 | +// err -> null |
| 414 | +// value.a -> 123 (number, not string) |
| 415 | + |
| 416 | +// or |
| 417 | +const result = schema.validate(value, schema); |
| 418 | +// result.error -> null |
| 419 | +// result.value -> { "a" : 123 } |
| 420 | +``` |
| 421 | + |
395 | 422 | #### `any.allow(value)`
|
396 | 423 |
|
397 | 424 | Whitelists a value where:
|
|
0 commit comments