Skip to content

Greater that & Less Than & equal & Different Field

Majid Ahmaditabar edited this page Dec 10, 2021 · 2 revisions

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.

data = {
   "num_diff": 234,
   "str_diff": "MQ234",
   "num_eq": 100,
   "str_eq": "MQ100",
   "num_gt": 101,
   "num_gte": 200,
   "str_gt": "MAQ200",
   "str_gte": "MQ200",
   "num_lt": 99,
   "num_lte": 199,
   "str_lt": "abc",
   "str_lte": "abcd",        
}

rules = {
   "num_diff": ["required", "different:233"],
   "str_diff": ["required", "different:MQ233"],
   "num_eq": ["required", "equal:100"],
   "str_eq": ["required", "equal:MQ100"],
   "num_gt": ["required", "gt:100"],
   "num_gte": ["required", "gte:200"],
   "str_gt": ["required", "gt:MQ200"],
   "str_gte": ["required", "gte:MQ200"],
   "num_lt": ["required", "lt:100"],
   "num_lte": ["required", "lte:200"],
   "str_lt": ["required", "lt:ABCD"],
   "str_lte": ["required", "lte:ABCD"],
}

validate = PyValidations.make(data, rules)
Clone this wiki locally