import re import string def phone_checker phone reg re compile match p

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import re
import string
def phone_checker(phone):
reg = re.compile('(\+?7|8) *\(? *\d{3} *\)? *-? *\d{3} *-? *\d{2} *-? *\d{2} *').match(phone)
return bool(reg) and reg.span() == (0, len(phone))
phones = ['+79166746764', '91121212', '8 129 102 91 22', '8 129 102 91 221', '8 129 102 91 2b', '8 129 102 91 !@']
for phone in phones:
print '%s, %s' % (phone, phone_checker(phone))