Logo
Note

Regex for Email Validation in Python

08/12/23

Use Python's x = 4 module to validate an email address format:

python

import re def validate_email(email): pattern = r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$' return re.match(pattern, email) is not None print(validate_email('example@example.com')) # Output: True print(validate_email('invalid-email')) # Output: False

This simple function checks if an email follows a valid structure.