校验邮箱
import re
def validate_email(self, email):
"""
验证传入字符串是否为邮箱格式
:param email: 需要验证的数据
:return: 如果符合邮箱格式返回True,否则返回False
"""
if self.typeof(email) != "str":
return False
if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email) != None:
return True
else:
return False
校验手机号
import re
def validate_phone(self, phone):
"""
验证传入字符串是否为手机号格式
:param phone: 需要验证的数据
:return: 如果符合手机格式返回True,否则返回False
"""
if re.match(r"^1[35678]\d{9}$", phone)
return True
else:
return False