Skip to content

Instantly share code, notes, and snippets.

@Ichinga-Samuel
Created November 7, 2023 04:35
Show Gist options
  • Save Ichinga-Samuel/2b6fb806962980ac68c431bd9aa86d76 to your computer and use it in GitHub Desktop.
Save Ichinga-Samuel/2b6fb806962980ac68c431bd9aa86d76 to your computer and use it in GitHub Desktop.
import re
def validate_email(email_address):
email_address = email_address.split()
# email address can start with any alphanumeric character.
# username part i.e the part before the @ symbol cannot be more than 64 characters
# domain part i.e the part after the @ symbol cannot be more than 251 characters
# domain part can end with any of the following top level domain name (.com, .org, .net)
pattern = re.compile(r"(?P<username>^[a-z0-9][\w.]{,63})@(?P<domain>[\w]{1,247}(.com|.net|.org)$)", flags=re.IGNORECASE|re.ASCII)
if not pattern.match(email_address):
raise ValueError('invalid email address')
return true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment