CSenshi / Validator

Easy-to-use, Highly Configurable Python Data Validator. Inspired by Laravel Validator
https://pypi.org/project/validator/
MIT License
46 stars 23 forks source link

Function as rule #58

Closed nikalosa closed 4 years ago

nikalosa commented 4 years ago

Enhance validator to read rule as a function

Example:

from validator import validate

def func_age(x):
    return x >= 18

# Dummy Checker
def func_mail(x):
    return "@" in x

rules = {"name": lambda x: len(x) > 1000,
         "age": func_age,
         "mail": func_mail}

req = {"name": "Jon",
       "age": 30,
       "mail": "JonDoe@gmail.com"}

validate(req, rules)