ansman/validate.js

Is there a way to validate with dependancies?

Closed this issue · 2 comments

Is there a way to define validate attribute dynamicaly? as a example

age : required,
guardianName: if age < 18 then required else notRequied

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.

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}
    };
  }