Skip to content

Commit

Permalink
temp commit - update maxLength.markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
AgniveshChaubey authored Feb 12, 2024
1 parent 5006f12 commit 67faecc
Showing 1 changed file with 0 additions and 46 deletions.
46 changes: 0 additions & 46 deletions content/2020-12/validation/maxLength.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,3 @@ related:
- vocabulary: format-annotation
keyword: format
---

The `maxLength` keyword is used to specify the maximum length of a string instance. It is used to enforce a constraint on the maximum number of characters allowed for a string instance.

* 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 less than or equal to the specified `maxLength`.

## Examples

{{<schema `Schema restricting string length to a maximum of 10 characters`>}}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string",
"maxLength": 10
}
{{</schema>}}

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

{{<instance-fail `An instance with a string length greater than 10 is invalid`>}}
"This is an invalid string"
{{</instance-fail>}}

{{<schema `Schema allowing either a string with a maximum of 20 characters or a numeric value`>}}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": [ "string", "number" ],
"maxLength": 20
}

{{</schema>}}

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

{{<instance-fail `An instance with a string length greater than 20 is invalid`>}}
"This description is too long"
{{</instance-fail>}}

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

0 comments on commit 67faecc

Please sign in to comment.