Is there a way to validate with dependancies?
Closed this issue · 2 comments
deep-link commented
Is there a way to define validate attribute dynamicaly? as a example
age : required,
guardianName: if age < 18 then required else notRequied
jakerobers commented
I would have two separate validators. One for dependents and one for guardians. Then you can split your data set by these two categories and validate separately.
ansman commented
Yes there is, here is an example from the documentation:
creditCardZip: function(value, attributes, attributeName, options, constraints) {
if (!(/^(34|37).*$/).test(attributes.creditCardNumber)) return null;
return {
presence: {message: "is required when using AMEX"},
length: {is: 5}
};
}