Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
47 changes: 47 additions & 0 deletions Robust Email Validator/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
def validate_email(email: str) -> bool:
email = email.strip().lower()

if '@' not in email or "." not in email:
print("You must include \"@\" and \".\" in your email!")
return False

try:
email, domain = email.split('@', 1)
except ValueError:
print("Email must contain exactly one \"@\" symbol")
return False
if not email:
print("You have nothing before the '@'!")
return False

if "." not in domain:
print("You are mising the '.'!")
return False

if domain.startswith('.') or domain.endswith('.'):
print("You placed the period at the incorrect location!")
return False

split_domain = domain.split(".")
if any(not part for part in split_domain):
return False

if len(split_domain[-1]) < 2:
return False

return True


test_emails = [
"john.doe@example.com",
" Jane@domain.org ",
"noatsymbol.com",
"@missinglocal.com",
"missingdot@domain",
"dot..error@domain.com",
"wrongend@domain.",
"short@domain.c"
]

for email in test_emails:
print(f"{email} -> {validate_email(email)}")