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"
]
# Start coding here. Use as many cells as you need.
#validate name if char length > 2
def validate_name(name):
    
    if type(name) != str:
        return False
    
    if len(name) > 2:
        return True
    else:
        return False
def validate_email(email):
    #first step
    #check if there is '@' symbol in email if there isn't, then the email is incorrect
    if '@' not in email:
        return False
    
    #second step
    #if the first step is satisfied, we will check if the email contains keywords inside top_level_domains
    for tld in top_level_domains:
        if tld in email:
            return True
    
    #if we didn't satisfy any of the conditions, we simply return false
    return False