Valid address

Valid address

Validation of an email address.

A valid email address consists of an email prefix and an email domain, both in acceptable formats. The prefix appears to the left of the @ symbol. The domain appears to the right of the @ symbol. For example, in the address example@mail.com, "example" is the email prefix, and "mail.com" is the email domain. Basic validation of an address is carried out client-side before data is sent to be processed server-side.

Make


Write a program that validates an email address.

Use this boilerplate code as a starting point:

Success Criteria

Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.

Acceptable email prefix formats:

  • Allowed characters: letters (a-z), numbers, underscores, periods, and dashes.
  • An underscore, period, or dash must be followed by one or more letter or number.

Acceptable email domain formats:

  • Allowed characters: letters, numbers, hyphen or period.
  • The domain must be at least three characters, for example: .com, .org, .cc

Complete the subprogram called `validate` that:

  1. Returns True if the `email_address` is valid or False if not.

Complete the `main program` so that:

  1. The user can input the email address to check.

Typical inputs and outputs from the program would be:

Enter your email address: abc-@mail.com

Email address is invalid.


Enter your email address: abc-d@mail.com

Email address is valid.


Enter your email address: abc..def@mail.com

Email address is invalid.


Enter your email address: abc.def@mail.com

Email address is valid.


Enter your email address: abc.def@mail.c@

Email address is invalid.


Enter your email address: abc.def@mail.cc

Email address is valid.

Knowledge Organiser

Use these resources as a reference to help you meet the success criteria.

Programming guide:

Evaluate


Run the unit tests below to check that your program has met the success criteria.

Enter your email address: name@domain.com

Email address is valid.

Enter your email address: n!me@domain.com

Email address is invalid.

Enter your email address: namedomain

Email address is invalid.

Enter your email address: name-123@domain

Email address is valid.

Enter your email address: name--123@domain

Email address is invalid.

Enter your email address: name@dom

Email address is valid.

Enter your email address: name@do

Email address is invalid.

Enter your email address: name@domain-123.com

Email address is valid.

Check that you have:

  • Used comments within the code to describe the purpose of subprograms, conditions and iterations.
  • Used meaningful identifier names. That means the names of subprograms and variables indicate what they are for.