Skip to content
Project: Building Core Sign-Up Functions to Help Validate New Users
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"
]validate_name() Implementation
# Start coding here. Use as many cells as you need.
def validate_name(name):
"""
Checks if the name is a string and longer than two characters.
Returns True if valid, False otherwise.
"""
if isinstance(name, str) and len(name.strip()) > 2:
return True
return False
validate_email() Implementation
def validate_email(email):
"""
Checks if the email contains '@' and ends with a valid top-level domain.
Returns True if valid, False otherwise.
"""
if not isinstance(email, str):
return False
email = email.strip().lower()
if "@" not in email:
return False
for tld in top_level_domains:
if email.endswith(tld):
return True
return False
Example Usage
print(validate_name("Amy")) # ✅ True
print(validate_name("Al")) # ❌ False
print(validate_name(123)) # ❌ False
print(validate_email("[email protected]")) # ✅ True
print(validate_email("[email protected]")) # ❌ False
print(validate_email("userexample.com")) # ❌ False