Hint
🧠 Not sure how to check if an email is valid?
Start by importing Python’s regular expression module:
import re
Then think about what makes up a valid email:
Something before the
@
symbolA domain name after the
@
A period and a domain ending like
.com
or.org
You can write a regex pattern like:
pattern = r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
To check if an email matches this pattern:
re.match(pattern, email)
If the match is not None
, the email is valid! Now wrap that into a function and test user input with it. Want to go one step further? Add a tkinter
interface so users can test emails visually.
🧪 Bonus hint: the pattern checks for characters before and after @
, and ensures there's a dot (.
) with letters after it.