Skip to content

Boolean

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

boolean

  • The field under validation must be able to be cast as a boolean. Accepted input are True, False , 1, 0.
data = {
     "bool_1": True,
     "bool_2": False,
     "bool_3": 0,
     "bool_4": 1,
     "bool_5": "1",
     "bool_6": "0",
     "bool_7": "false",
     "bool_8": "true",
}

rules = {
     "bool_1": ["required", "boolean"],
     "bool_2": ["required", "boolean"],
     "bool_3": ["required", "boolean"],
     "bool_4": ["required", "boolean"],
     "bool_5": ["required", "boolean"],
     "bool_6": ["required", "boolean"],
     "bool_7": ["required", "boolean"],
     "bool_8": ["required", "boolean"],        
}

validate = PyValidations.make(data, rules)

bool 5,6,7,8 is wrong so validator will return:

{
 'errors': {
     'bool_5': ['The  bool_5 may only boolean value : true , false , 1 or 0.'],
     'bool_6': ['The  bool_6 may only boolean value : true , false , 1 or 0.'],
     'bool_7': ['The  bool_7 may only boolean value : true , false , 1 or 0.'],
     'bool_8': ['The  bool_8 may only boolean value : true , false , 1 or 0.']
   },
   
  'failed': True
}
Clone this wiki locally