From 7361f831fb0308aa8a3a7e34ea171fd6bb3b8e5d Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Fri, 10 Feb 2017 22:08:41 +0000 Subject: [PATCH] docs: custom formats for numbers, closes #291 --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d307759b..1e3df5363 100644 --- a/README.md +++ b/README.md @@ -899,7 +899,7 @@ If no parameter is passed all schemas but meta-schemas will be removed and the c ##### .addFormat(String name, String|RegExp|Function|Object format) -Add custom format to validate strings. It can also be used to replace pre-defined formats for Ajv instance. +Add custom format to validate strings or numbers. It can also be used to replace pre-defined formats for Ajv instance. Strings are converted to RegExp. @@ -910,6 +910,7 @@ If object is passed it should have properties `validate`, `compare` and `async`: - _validate_: a string, RegExp or a function as described above. - _compare_: an optional comparison function that accepts two strings and compares them according to the format meaning. This function is used with keywords `formatMaximum`/`formatMinimum` (defined in [ajv-keywords](https://github.com/epoberezkin/ajv-keywords) package). It should return `1` if the first value is bigger than the second value, `-1` if it is smaller and `0` if it is equal. - _async_: an optional `true` value if `validate` is an asynchronous function; in this case it should return a promise that resolves with a value `true` or `false`. +- _type_: an optional type of data that the format applies to. It can be `"string"` (default) or `"number"` (see https://github.com/epoberezkin/ajv/issues/291#issuecomment-259923858). If the type of data is different, the validation will pass. Custom formats can be also added via `formats` option.