pip install cerberus
python
from cerberus import Validator
python
def validate_phone(field, value, error):
if not re.match(r'^\+?1?\d{9,15}$', value):
error(field, "Invalid phone number")
python
v = Validator()
v.validators['phone'] = validate_phone
python
document = {'phone': '1234567890'}
if v.validate(document):
print("Validation successful")
else:
print(v.errors)
python
import re
from cerberus import Validator
def validate_phone(field, value, error):
if not re.match(r'^\+?1?\d{9,15}$', value):
error(field, "Invalid phone number")
v = Validator()
v.validators['phone'] = validate_phone
document = {'phone': '1234567890'}
if v.validate(document):
print("Validation successful")
else:
print(v.errors)