Closed zhaoyi0113 closed 7 years ago
You can use the present
rule
// Should fail
new Validator({}, {
name: 'string|present'
);
// Should fail
new Validator({
name: []
}, {
name: 'string|present'
);
Thanks for your answer. It should work. Is there a way for me to place more complex logic on the validation rule for that? Can I inject a function into the rule to do some validate calculation?
@zhaoyi0113 You can create your own rule if you would like to be as verbose as you wish
https://github.com/skaterdav85/validatorjs#registering-custom-validation-rules
If this does not do what you need, let me know and I will have a closer look at what you are trying to do.
Thanks for your help.
@zhaoyi0113 sure thing 👍
I have two form fields and they have a dependency. The second field is required only if the first field value is true. How can I add such dependent validation rules on the second field?