Menu
Coddy logo textTech

Domain name

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

john@gmail.com

The bold part is the domain name.

The domain name is a string of letters and digits that defines a space on the Internet owned and controlled by a specific mailbox provider or organization.

Domain names may be a maximum of 253 characters and consist of:

  • Uppercase and lowercase letters in English (A-Z, a-z)
  • Digits from 0 to 9 
  • A hyphen (-)
  • A period (.)  (used to identify a sub-domain; for example,  creator.coddy)
challenge icon

Challenge

Easy

Add to validate support for domain name validation.

In out validator we will support easier terms, the recipient name should be a maximum of 12 characters and minimum of 3 characters long and consist of:

  • Uppercase and lowercase letters in English (A-Z, a-z)
  • Digits from 0 to 9
  • A hyphen (-)

As before the function validate should return true if the input email is valid, and now also with domain name validation

You don't need to support sub-domains, you can expect no domain name with a period (.) exists.

Try it yourself

PERMITS = '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:
            return False
    if '.' == recipient_name[0] or '.' == recipient_name[-1] or '_' == recipient_name[0] or '_' == recipient_name[-1]:
        return False
    return True
    

All lessons in Email validator using Python