You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

26 lines
824 B

# coding=utf-8
import re
from django.core.exceptions import ValidationError
phone_regex = re.compile('^((9|4)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{10}$')
def check_phone(phone):
return re.match(phone_regex, str(phone)) is not None
def check_phone_with_except(phone):
if re.match(phone_regex, phone) is None:
raise ValidationError(u'Телефон не прошел проверку %s' % phone)
def check_email(email):
p = re.compile(
r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string
r')@(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$', re.IGNORECASE)
m = p.match(email)
if m:
return True
else:
return False