bash pip install cerberus python schema = { 'name': {'type': 'string', 'required': True}, 'age': {'type': 'integer', 'min': 18, 'max': 99}, 'email': {'type': 'string', 'regex': '[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+'} } python from cerberus import Validator data = { 'name': 'John Doe', 'age': 25, 'email': 'johndoe@example.com' } validator = Validator(schema) is_valid = validator.validate(data) if is_valid: else: python from cerberus import Validator class CustomValidator(Validator): def _validate_name(self, name, field, value): if not value.isalpha(): data = { 'name': 'John Doe', 'age': 25, 'email': 'johndoe@example.com' } validator = CustomValidator(schema) is_valid = validator.validate(data) if is_valid: else:


上一篇:
下一篇:
切换中文