forked from brazilian-utils/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail.py
More file actions
29 lines (22 loc) · 815 Bytes
/
Copy pathemail.py
File metadata and controls
29 lines (22 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import re
def is_valid(email): # type: (str) -> bool
"""
Check if a string corresponds to a valid email address.
Args:
email (str): The input string to be checked.
Returns:
bool: True if email is a valid email address, False otherwise.
Example:
>>> is_valid("brutils@brutils.com")
True
>>> is_valid("invalid-email@brutils")
False
.. note::
The rules for validating an email address generally follow the
specifications defined by RFC 5322 (updated by RFC 5322bis),
which is the widely accepted standard for email address formats.
"""
pattern = re.compile(
r"^(?![.])[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
)
return isinstance(email, str) and re.match(pattern, email) is not None