Skip to content

You recently joined a small startup as a junior developer. The product managers have come to you for help improving new user sign-ups for the company's flagship mobile app.

There are lots of invalid and incomplete sign-up attempts crashing the app. Before creating new accounts, you suggest standardizing validation checks by writing reusable Python functions to validate names, emails, passwords, etc. The managers love this idea and task you with coding core validation functions for improving sign-ups. It's your job to write these custom functions to check all user inputs to ensure they meet minimum criteria before account creation to reduce crashes.

# Re-run this cell
# Preloaded data for validating email domain.
top_level_domains = [
    ".org",
    ".net",
    ".edu",
    ".ac",
    ".gov",
    ".com",
    ".io"
]
def validate_name(user_name: str):
    # Check if input is a string
    if not isinstance(user_name, str):
        return False
    # Check minimum length
    if len(user_name) < 3:
        return False
    return True

def validate_email(user_email: str):
    # Check for presence of '@'
    if "@" not in user_email:
        return False
    # Check for valid top-level domain
    if not any(user_email.endswith(tld) for tld in top_level_domains):
        return False
    return True