Validation error message of a rule can be customized by passing customMessage param to the rule.
Validation Result: valid
Current Rules
[
{
"path": "val1",
"ruleSet": [
"required",
{
"rule": "length",
"greaterThan": 8,
"customMessage": "This field's length is ${value}, however it should be greater than ${comparisonValue}"
}
]
},
{
"path": "val2",
"ruleSet": [
"required",
{
"rule": "length",
"equalTo": 5,
"customMessage": e=>e.value>e.comparisonValue?`This field's length should be ${e.comparisonValue}, your input's (${e.value}) is greater than this value`:`This field's length should be ${e.comparisonValue}, your input's (${e.value}) is less than this value`
}
]
},
{
"path": "val3",
"ruleSet": [
"required",
{
"rule": "myCustomRule2",
"customMessage": "Hello, this is myCustomRule2 customMessage. This field is not valid, because text ${value} should either include letter 'a' or its length should be greater than 4"
}
]
},
{
"path": "val4",
"ruleSet": [
{
"rule": "required",
"customMessage": {
"type": "span",
"key": null,
"ref": null,
"props": {
"children": [
"This field is ",
{
"type": "b",
"key": null,
"ref": null,
"props": {
"children": " required "
},
"_owner": null
}
]
},
"_owner": null
}
},
{
"rule": "length",
"equalTo": 6,
"customMessage": e=>(0,p.jsxs)("span",{children:["This field","'","s length should be ",(0,p.jsxs)("b",{children:[e.comparisonValue," "]}),", your input length is"," ",(0,p.jsxs)("b",{children:[" ",e.value," "]})]})
}
]
}
]