Closed MaxChri closed 1 year ago
@MaxChri this happens because parameters are not shared between rule instances on the same attribute. I'll need to think how to handle this as parameter names are not unique across rules so a general collection would result in collisions e.g. different
and required_if
both define field
@MaxChri 1.6.0 now allows referencing parameters from related rules on the same attribute. You can define a custom message using :<rule_name>.<parameter>
so in your example if would be :between.min
and :between.max
on the regex message rule.
@dave-redfern it works perfectly. Thank you very much!
If you use for example:
"password": "required|between:8,16|regex:/^[\\da-zA-Z!$%+.]+$/"
Parameters like ":min" and ":max" are undeclared if the string is between 8-16 characters. The problem is that the "regex" validation could fail while "between" parameter is fine. If that happens, you will have a wrong response message with missing (e.g min/max) variables.
Custom response message: Your password must have between :min and :max characters and only [! $ % + .] as special characters.
How it should look like: Your password must have between 8 and 16 characters and only [! $ % + .] as special characters.
As you can see, instead of showing the parameter values, the key will be displayed in the response. If your password is not between 8-16 characters, the response is correct, showing the actual values instead of the keys. This issue was still there with rakit validatior.