Implements an is valid email address algorithm
@ https://en.wikipedia.org/wiki/Email_address
|
Returns True if the passed email address is valid. |
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.
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.
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.
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