-1
I have a type parameter number
and I want to validate the size, how can I do this using the function maximum
in a jsonschema
?
"type": ["number","null" ], "description": "Maximum Field Length - (23,8)"
-1
I have a type parameter number
and I want to validate the size, how can I do this using the function maximum
in a jsonschema
?
"type": ["number","null" ], "description": "Maximum Field Length - (23,8)"
1
As commented, you want to validate that your number has up to 23 characters in the whole part and 8 characters in the decimal part. You don’t do it with numbers, you do it with strings.
The guy string
has the validations minLength
, maxLength
and pattern
:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"price": {
"type": "string",
"minLength": 3,
"maxLength": 32,
"pattern": "^\\d{1,23}\\.\\d{1,8}$"
}
}
}
Thus, the JSON below is valid:
{
"price": "123.456789"
}
But the JSON below does not, as it has more than 8 characters in the decimal part.
{
"price": "123.4567890123"
}
-1
I think the best way to validate this would be to input the data with a
if (description.length< maxField)
But I could do so
{
"type": "string",
"minLength": 2,
"maxLength": 3
}
Browser other questions tagged javascript
You are not signed in. Login or sign up in order to post.
Well, it’s not enough to use the
maximum
as you yourself commented?{"type": "number", "maximum": 20}
– Woss
Hello Anderson, yes I have to use the function Maximum, but I do not know how to implement (23,8) with so much.
– Elvis Mota
And what does "(23.8) mean as maximum size"? The value must be less than 23.8?
– Woss
23 digits and 8 decimal places
– Elvis Mota