blahblah blahblah - 1 month ago 9
JSON Question

How to customise error message for invalid input?

How to customise error message for invalid input?

{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"username": {
"type": "string",
"pattern": "^[A-Za-z0-9-_.]+$",
"minLength": 3
},
"password": {
"type": "string",
"minLength": 8,
"pattern": "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d\\W]$"
}
},
"required": [
"username",
"password"
],
"errors": [
{
"property": "username",
"message": "min 3 characters, do not use spaces or special characters"
}
]
}


For example, if username input is not of required min length or doesn't satisfy regex pattern, display one custom message
min 3 characters, do not use spaces or special characters

Answer

Custom error messages are not supported. However, there is some discussion going on to add a feature like this in the next version of JSON Schema.

Comments