天天看點

Python 驗證手機号碼和郵箱

import re
def validate_mobile(value):
    if not re.search('^1[0-9]{10}$', str(value)):
        raise ValidationError("mobile format error", "mobile_format")
    return True

def validate_email(value):
    if not re.search('\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*', str(value)):
        raise ValidationError("email format error", "email_format")
    return True