Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upEquality with another attribute #29
Comments
This comment has been minimized.
This comment has been minimized.
validate.validators.equality = function(value, options, key, attributes) {
var other = attributes[options.attribute];
if (value !== other) {
var attr = validate.prettify(options.attribute);
return options.message ||
validate.format("is not equal to %{a}", {a: attr});
}
};
var constraints = {
a1: {
equality: {
attribute: "a2"
}
}
};
console.log(validate({}, constraints));
// => undefined
console.log(validate({a1: "foo", a2: "foo"}, constraints));
// => undefined
console.log(validate({a1: "foo", a2: "bar"}, constraints));
// => {a1: ["A1 is not equal to a2"]} Hope this helps. It doesn't work with nested attributes ( |
This comment has been minimized.
This comment has been minimized.
@ansman Thank you for code and I'm sorry for my inattention. Also I think it makes sense to add this type of a validator to the predefined list in the documentation. It's really a common task to check equality for email, password fields, etc. |
This comment has been minimized.
This comment has been minimized.
Yeah, that seems like a good idea. I'll implement it for a future release. |
ansman
closed this
in
52fd2a4
Mar 7, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dmhts commentedFeb 10, 2015
I'm wondering how to check the equality with another attribute? I've looked through the documentation and haven't found any possibility to define a custom validator only the dynamic one. Did I miss something?