strings.is_valid_email_address ============================== .. py:module:: strings.is_valid_email_address .. autoapi-nested-parse:: Implements an is valid email address algorithm @ https://en.wikipedia.org/wiki/Email_address Attributes ---------- .. autoapisummary:: strings.is_valid_email_address.MAX_DOMAIN_OCTETS strings.is_valid_email_address.MAX_LOCAL_PART_OCTETS strings.is_valid_email_address.email_tests strings.is_valid_email_address.is_valid Functions --------- .. autoapisummary:: strings.is_valid_email_address.is_valid_email_address Module Contents --------------- .. py:function:: is_valid_email_address(email: str) -> bool Returns True if the passed email address is valid. The local part of the email precedes the singular @ symbol and is associated with a display-name. For example, "john.smith" The domain is stricter than the local part and follows the @ symbol. Global email checks: 1. There can only be one @ symbol in the email address. Technically if the @ symbol is quoted in the local-part, then it is valid, however this implementation ignores "" for now. (See https://en.wikipedia.org/wiki/Email_address#:~:text=If%20quoted,) 2. The local-part and the domain are limited to a certain number of octets. With unicode storing a single character in one byte, each octet is equivalent to a character. Hence, we can just check the length of the string. Checks for the local-part: 3. The local-part may contain: upper and lowercase latin letters, digits 0 to 9, and printable characters (!#$%&'*+-/=?^_`{|}~) 4. The local-part may also contain a "." in any place that is not the first or last character, and may not have more than one "." consecutively. Checks for the domain: 5. The domain may contain: upper and lowercase latin letters and digits 0 to 9 6. Hyphen "-", provided that it is not the first or last character 7. The domain may also contain a "." in any place that is not the first or last character, and may not have more than one "." consecutively. >>> for email, valid in email_tests: ... assert is_valid_email_address(email) == valid .. py:data:: MAX_DOMAIN_OCTETS :value: 255 .. py:data:: MAX_LOCAL_PART_OCTETS :value: 64 .. py:data:: email_tests :type: tuple[tuple[str, bool], Ellipsis] :value: (('simple@example.com', True), ('very.common@example.com', True),... .. py:data:: is_valid :value: False