Greater that & Less Than & equal & Different Field - MajAhd/elx_validation GitHub Wiki

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"]
      },
]