I'm working on a script that allows users to input an email. If the email has a 'username' and 'domain' such as username@domain.com, then the program should output that the email is an email. If the user enters something such as username@, then the program should output that the input is not a valid email address.
The function should return True when the text is an email, otherwise it should return False.
I'm having a problem getting the program to return False when entering an address like 'username@' or '@gmail.com'.
I currently have the following code:
text = ''
tokens = 0
split_counter = 0
def isEmail(text):
tokens = text.split('@')
split_counter = len(tokens)
if split_counter == 2:
print(text, '==> EMAIL')
else:
print(text, '==> NOT EMAIL')
return
while True:
text = input("Email: ")
if text == 'quit':
print('Later!')
break
else:
isEmail(text)
Thank you.