Menu
Coddy logo textTech

Top-level domain

Lesson 5 of 8 in Coddy's Email validator using Python course.

john@gmail.com

The bold part is the top-level domain name.

Top-level domains are the highest level of the domain name system for the Internet and is placed after the domain name in an email address.

Common top-level domains are:

  • com
  • net
  • org
challenge icon

Challenge

Easy

Add to validate support for top-level domain name validation.

In out validator we will support easier terms, check that the top-level domain name is one of these:

  • com
  • net
  • org
  • tech

Any other name should return False!

Try it yourself

PERMITS_RECIEPENT = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._'
PERMITS_DOMAIN = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-'

def validate(email):
    if not email.count('@') == 1:
        return False

    recipient_name = email.split('@')[0]
    if len(recipient_name) > 24 or len(recipient_name) < 3:
        return False
    for c in recipient_name:
        if c not in PERMITS_RECIEPENT:
            return False
    if '.' == recipient_name[0] or '.' == recipient_name[-1] or '_' == recipient_name[0] or '_' == recipient_name[-1]:
        return False
    
    domain_name = email.split('@')[1].split('.')[0]
    if len(domain_name) > 12 or len(domain_name) < 3:
        return False
    for c in domain_name:
        if c not in PERMITS_DOMAIN:
            return False
    return True
    

All lessons in Email validator using Python