Email Validation with Regex

Using regular expressions to validate email addresses

Python
import re

def validate_email(email):
    pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
    return re.match(pattern, email) is not None

emails = ['[email protected]', 'invalid.email@com', '[email protected]']
for email in emails:
    print(f"{email}: {'Valid' if validate_email(email) else 'Invalid'}")
Click Run or press shift + ENTER to run code.