Created
November 7, 2023 04:35
-
-
Save Ichinga-Samuel/2b6fb806962980ac68c431bd9aa86d76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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