Filtering string in Python
- by Ecce_Homo
I am making algorithm for checking the string (e-mail) - like "E-mail addres is valid" but their are rules. First part of e-mail has to be string that has 1-8 characters (can contain alphabet, numbers, underscore [ _ ]...all the parts that e-mail contains) and after @ the second part of e-mail has to have string that has 1-12 characters (also containing all legal expressions) and it has to end with top level domain .com
EDIT
email = raw_input ("Enter the e-mail address:")
length = len (email)
if length > 20
print "Address is too long"
elif lenght < 5:
print "Address is too short"
if not email.endswith (".com"):
print "Address doesn't contain correct domain ending"
first_part = len (splitting[0])
second_part = len(splitting[1])
account = splitting[0]
domain = splitting[1]
for c in account:
if c not in "abcdefghijklmopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.":
print "Invalid char", "->", c,"<-", "in account name of e-mail"
for c in domain:
if c not in "abcdefghijklmopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.":
print "Invalid char", "->", c,"<-", "in domain 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"
else: # if everything is fine return this
print "E-mail addres is valid"
EDIT:
After reproting what is wrong with our input, now I need to make Python recognize valid address and return ("E-mail adress is valid")
This is the best i can do with my knowledge....and we cant use regular expressions, teacher said we are going to learn them later.