validator
is an optional key for components used to validate input strings before execution.
It allows you to specify constraints and custom error messages about string validation.
You can use four kinds of constraints.
exist
: Ensures the input path exists.not_empty
: Requires the input string to be non-empty.regex
: Validates the input against a regex pattern.wildcard
: Validates the input against a wildcard pattern.
{
"type": "file",
"label": "Some file path",
"validator": {
"exist": true,
"not_empty": true,
"regex": "^[\\w]+\\.png$",
"wildcard": "*.png"
}
}
Warning
The regex validator does NOT support some operators like the group ()
operator.
See here for a list of supported operators.
You can overwrite default error messages using *_error
options.
{
"type": "file",
"label": "Some file path",
"validator": {
"exist": true,
"exist_error": "File does not exist!!!",
"not_empty": true,
"not_empty_error": "Type something...",
"regex": "^[\\w]+\\.png$",
"regex_error": "Only alphanumeric characters are supported.",
"wildcard": "*.png",
"wildcard_error": "Not PNG!"
}
}