Строка фильтрации в Python

Я делаю алгоритм проверки строки (e -mail)-например, «Почтовый адрес E -действителен», но это правила.Первая часть электронной -почты должна быть строкой, состоящей из 1 -8 символов (может содержать алфавит, цифры, подчеркивание [_]... все части, которые содержит электронная -почта )и после @ во второй части e -почта должна иметь строку из 1 -12 символов (, содержащую также все допустимые выражения ), и она должна заканчиваться доменом верхнего уровня.com

email = raw_input ("Enter the e-mail address:")
length = len (email)
if length > 20 
    print "Address is too long"
elif lenght < 7:
    print "Address is too short"  
if not email.endswith (".com"):   
    print "Address doesn't contain correct domain ending"   
try:
    first_part = len (splitting[0])
    second_part = len(splitting[1])  

    account = splitting[0]
    domain = splitting[1] 

    list = "abcdefghijklmopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_."

    for c in account: 
        if c not in list:
            print "Invalid char", "->", c,"<-", "in account name of e-mail"

    for c in domain:
        if c not in list:
            print "Invalid char", "->", c,"<-", "in domain name of  e-mail"

    if first_part == 0:
        print "You need at least 1 character before the @"
    elif first_part> 8:
        print "The first part is too long"
    if second_part == 4:
        print "You need at least 1 character after the @"
    elif second_part> 16:
        print "The second part is too long"
except IndexError:
        print ""The address must consist of 2 parts connected with symbol @,\
 and ending must be.com"

    if first_part > 0 and first_part < 8 and second_part >4 and second_part < 16:
       print "Valid e-mail address"
5
задан 24 revs, 5 users 68% 18 October 2012 в 15:12
поделиться