Skip to content

input4mips_validation.validation.email#

input4mips_validation.validation.email #

Validation of emails

validate_email(email) #

Validate that a value might be a valid email

This won't catch everything (so use with some caution), but it will catch things which are clearly wrong.

Parameters:

Name Type Description Default
email str

Email to validate

required

Raises:

Type Description
ValueError

email is clearly not an email

Source code in src/input4mips_validation/validation/email.py
def validate_email(email: str) -> None:
    """
    Validate that a value might be a valid email

    This won't catch everything (so use with some caution),
    but it will catch things which are clearly wrong.

    Parameters
    ----------
    email
        Email to validate

    Raises
    ------
    ValueError
        `email` is clearly not an email
    """
    check_res = eutils.parseaddr(email)

    if "@" not in check_res[1]:
        msg = f"The given value is clearly not an email. Received {email=}"
        raise ValueError(msg)