Skip to content

Commit

Permalink
add description and examples for minLength keyword (#109)
Browse files Browse the repository at this point in the history
This PR addressed #89
  • Loading branch information
AgniveshChaubey authored Feb 20, 2024
1 parent 828b446 commit 469a4b6
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions content/2020-12/validation/minLength.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,49 @@ related:
- vocabulary: format-annotation
keyword: format
---

The `minLength` keyword is used to specify the minimum length of a string instance. It defines the minimum number of characters that a valid string must have to satisfy the schema.

* Applies only to string data types.
* Value must be a non-negative integer.
* String length is counted in characters, not bytes.
* Validation succeeds if the string length is greater than or equal to the specified `minLength`.

## Examples

{{<schema `Schema requiring minimum string length of 5`>}}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string",
"minLength": 5
}
{{</schema>}}

{{<instance-pass `An instance with a string length greater than or equal to 5 is valid`>}}
"This is a valid string"
{{</instance-pass>}}

{{<instance-fail `An instance with a string length less than 5 is invalid`>}}
"foo"
{{</instance-fail>}}

{{<schema `Schema which allows either a string with at least 3 characters or a numeric value`>}}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": [ "string", "number" ],
"minLength": 3
}

{{</schema>}}

{{<instance-pass `An instance with a string length greater than or equal to 3 is valid`>}}
"foo"
{{</instance-pass>}}

{{<instance-fail `An instance with a string length less than 3 is valid`>}}
"hi"
{{</instance-fail>}}

{{<instance-pass `An instance with a numeric value is valid`>}}
55
{{</instance-pass>}}

0 comments on commit 469a4b6

Please sign in to comment.