Python: email-validator验证Email地址
文档:
- PyPI: https://pypi.org/project/email-validator/
- Github: https://github.com/JoshData/python-email-validator
安装
pip install email-validator
代码实例
from email_validator import validate_email, EmailNotValidError
email = "my+address@mydomain.tld"
try:
# Validate.
valid = validate_email(email)
# Update with the normalized form.
email = valid.email
except EmailNotValidError as e:
# email is not valid, exception message is human-readable
print(str(e))