ElxValidation.Different (elx_validation v0.1.3)
different:value
- The field under validation must have a different value than field.
equal:value
- The field under validation must be equal to the given field. The two fields must be of the same type. Strings and numerics are evaluated using the same conventions as the size rule.
gt:value
- The field under validation must be greater than the given field. The two fields must be of the same type. Strings and numerics are evaluated using the same conventions as the size rule.
gte:value
- The field under validation must be greater than or equal to the given field. The two fields must be of the same type. Strings and numerics are evaluated using the same conventions as the size rule.
lt:value
- The field under validation must be less than the given field. The two fields must be of the same type. Strings and numerics are evaluated using the same conventions as the size rule.
lte:value
- The field under validation must be less than or equal to the given field. The two fields must be of the same type. Strings and numerics are evaluated using the same conventions as the size rule.
examples
data = %{
num_diff: 234 --> not be 233
str_diff: "MQZVD" --> not be ABCD
}
rules = [
%{
field: "num_diff",
validate: ["different:233"]
},
%{
field: "str_diff",
validate: ["different:ABCD"]
}
]
data = %{
num_eq: 100, --> must be 100
str_eq: "abcd" --> must be "abcd"
}
rules = [
%{
field: "num_eq",
validate: ["equal:100"]
},
%{
field: "str_eq",
validate: ["equal:abcd"]
},
]
data = %{
num_gt: 101, --> greater than 100
num_gte: 200, --> greater than or equal 200
str_gt: "abcd", --> length of this must greater than length of abc(3 char)
str_gte: "abcd" --> length of this must greater than or equal length of abc(3 char)
}
rules = [
%{
field: "num_gt",
validate: ["gt:100"]
},
%{
field: "num_gte",
validate: ["gte:200"]
},
%{
field: "str_gt",
validate: ["gt:abc"]
},
%{
field: "str_gte",
validate: ["gte:abc"]
},
]
data = %{
num_lt: 99, --> less than 100
num_lte: 199, --> less than or equal 200
str_lt: "ab", --> length of this must less than length of abc(3char)
str_lte: "abcd" --> length of this must less than length of abcde(5 char)
}
rules = [
%{
field: "num_lt",
validate: ["lt:100"]
},
%{
field: "num_lte",
validate: ["lte:200"]
},
%{
field: "str_lt",
validate: ["lt:ABC"]
},
%{
field: "str_lte",
validate: ["lte:ABCDE"]
},
]
Link to this section Summary
Functions
target has to equal to value
target has to greater than value
target has to equal or greater than value
target has to different with value
target has to less than value
target has to equal or less than value
Link to this section Functions
Link to this function
equal(target, value)
target has to equal to value
Link to this function
gt(target, value)
target has to greater than value
Link to this function
gte(target, value)
target has to equal or greater than value
Link to this function
is_different(target, value)
target has to different with value
Link to this function
lt(target, value)
target has to less than value
Link to this function
lte(target, value)
target has to equal or less than value