Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string length documentation #13

Merged
merged 1 commit into from
May 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions docs/design/specification/model-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,22 @@ We guarantee to support values that are included by the ISO 8601-1:2019, RFC 333
| `default` | declares a default value for the property, if no value is specified|
| `range` | declares a valid range for numeric properties|
| `regex` | declares a validation regex for string properties|
| `length` | declares a minimum and maximum char length for string properties|

`String` fields may include an optional regular expression, which is used to validate the contents of the field. Careful use of field validators allows Concerto to perform rich data validation, leading to fewer errors and less boilerplate application code.

The example below validates that a `String` variable starts with `abc`:

```
o String myString regex=/abc.*/
o String myString regex=/abc.*/
```

`String` fields may also include an optional length expression, which is used to validate the number of characters in the string field. Both the minimum and maximum length bound are optional, however at least one must be specified. The maxLength must be greater than or equal to the minLength.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment that the bounds are inclusive (I see that you have this explained in the example below).

Also, do you think that we need a warning about this behaviour?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length#strings_with_length_not_equal_to_the_number_of_characters


```
o String stringLengthWithMinMaxLength length=[1,100] // greater than or equal to 1 and less than or equal to 100
o String stringLengthWithMinLength range=[1,] // greater than or equal to 1
o String stringLengthWithMaxLength range=[,100] // less than or equal to 100
```

`Double`, `Long` or `Integer` fields may include an optional range expression, which is used to validate the contents of the field. Both the lower and upper bound are optional, however at least one must be specified. The upper bound must be greater than or equal to the lower bound.
Expand All @@ -75,7 +84,7 @@ The example below validates that a `String` variable starts with `abc`:

```
asset Vehicle {
o String model default="F150"
o String model default="F150" length=[1,100]
o String make default="FORD"
o Integer year default=2016 range=[1990,] optional // model year must be 1990 or higher
o String V5cID regex=/^[A-z][A-z][0-9]{7}/
Expand Down