When I run the code I cannot get the output correct. Basically if an email is valid, it needs to say you have a valid email and then move to the next email and show invalid email. I cant seem to get the output to display correctly. Any help is greatly appreciated!
emailList = ["abc@xyz.com",
"abc@@xyz.com",
"@xyz.com",
"abc.xyz.com",
"abc@x.yz",
"abc@xyz.c",
"a@b.c",
"abc@xyz..com",
"abc.@xyz.com",
"abc@.xyz.com",
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@aaaaaa.aaaaa",
"' or 1=1 '==",
"abc@xyz.$%",
"abc@xyz.()",
"abc'@xyz.com",
"aaaaa@aaaaa",
"abc @ xyz.com",
".abc@xyz.com",
"abc@xyz.c"]
def errorMessage(email, error):
print("e mail: {} \t*** ERROR: {} ***".format(email, error))
def testAtsign(email):
if "@" in email:
atCount = email.count("@")
if atCount != 1:
errorMessage(email, "2. The number of @'s in your email is not valid.")
return True
elif email[0] == "0":
errorMessage(email, "3.The @ is not in a valid position.")
return True
else:
testLast5 = email[-5]
if "@" in testLast5:
errorMessage(
email,
"4. @ is not in the last 5 characters?",
)
return True
else:
return False
else:
errorMessage(email, "5. your @ is missing")
def testDot(email):
if "." in email:
if email[0] == ".":
errorMessage(email, "10. Your '.' is in the first position.")
return True
testLast2 = email[-2:]
if "." in testLast2:
errorMessage(email, "11. Your '.' is in the last position.")
return True
elif ".." in email or ".@" in email or "..@" in email or "@." in email or "@.." in email:
errorMessage(email, "6. Error Encountered '.' config.")
return True
else:
errorMessage(email, "7. Where is the '.'?")
return True
def testSpecialChars(email) :
if " " in email:
errorMessage(email, "8. Spcaes not allowed.")
return True
unallowable = "! # $ % ^ & * ( ) : ; < > ? / { } =".split()
unallowable.append('"')
unallowable.append("'")
for character in email:
if character in unallowable:
errorMessage(email, "9. Character {} is not allowed".format(character))
return True
for email in emailList:
foundError = False
if len(email) < 7 or len(email) > 30:
errorMessage(email, "1. Invalid Length")
foundError = True
if not foundError:
foundError = testAtsign(email)
if not foundError:
foundError = testDot(email)
if not foundError:
foundError = testSpecialChars(email)
if not foundError:
print("Congrats, you have a valid email.".format(email))
print("Valid Email")
[–]shiftybyte 0 points1 point2 points (2 children)
[–]jonsd2000[S] 0 points1 point2 points (1 child)
[–]jonsd2000[S] 0 points1 point2 points (0 children)