strings.is_valid_email_address¶
Implements an is valid email address algorithm
@ https://en.wikipedia.org/wiki/Email_address
Attributes¶
Functions¶
|
Returns True if the passed email address is valid. |
Module Contents¶
- strings.is_valid_email_address.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:
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,)
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:
The local-part may contain: upper and lowercase latin letters, digits 0 to 9, and printable characters (!#$%&’*+-/=?^_`{|}~)
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:
The domain may contain: upper and lowercase latin letters and digits 0 to 9
Hyphen “-”, provided that it is not the first or last character
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
- strings.is_valid_email_address.MAX_DOMAIN_OCTETS = 255¶
- strings.is_valid_email_address.MAX_LOCAL_PART_OCTETS = 64¶
- strings.is_valid_email_address.email_tests: tuple[tuple[str, bool], Ellipsis] = (('simple@example.com', True), ('very.common@example.com', True),...¶
- strings.is_valid_email_address.is_valid = False¶