Skip to content

Accepted

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

accepted

  • The field under validation must be "yes", "on", 1, or "true" . This is useful for validating "Terms of Service" acceptance or similar fields.
data = {
    "accept_1": "on",
    "accept_2": "yes",
    "accept_3": "true",
    "accept_4": 1,
    "accept_5": "1",
    "accept_6": "off",
    "accept_7": "false",
    "accept_8": "0",
}

rules = {
     "accept_1": ["required", "accepted"],
     "accept_2": ["required", "accepted"],
     "accept_3": ["required", "accepted"],
     "accept_4": ["required", "accepted"],
     "accept_5": ["required", "accepted"],
     "accept_6": ["required", "accepted"],
     "accept_7": ["required", "accepted"],
     "accept_8": ["required", "accepted"],
}

validate = PyValidations.make(data, rules)

it returns :

{
 
 'failed': True,
  
  'errors': {
     'accept_6': ['The accept_6 must be accepted.'],
     'accept_7': ['The accept_7 must be accepted.'],
     'accept_8': ['The accept_8 must be accepted.']
    },
}
Clone this wiki locally