Question: Java This problem has you build a simple email address validation application. Use sequential if structures, not nested. You're going to use String methods with

Java This problem has you build a simple email address validation application. Use sequential if structures, not nested.

You're going to use String methods with if structures to validate an email address against some key factors. It won't be perfect or complete as assigned here, but it will get you started with some practical coding we can build on later.

Email addresses have one @ symbol only. The characters to the left of the @ symbol are called the local part, the characters to the right are called the domain part. A little background, although not essential for this problem:

  1. String length is between 4 and 320 characters

Invalid length

Proceed with the rest of the tests ONLY if the length is valid. Otherwise, display the error and end.

  1. Contains only one @ symbol

More than one @ found

Find the first occurance in the full email address variable. To check for more, create another variable from a substring starting with the character to the right of the first @ symbol all the way to the end. Then, check it to see if it contains an @. If it does, you've got at least one.

  1. The length of the local part is 1 to 64

More than 64 characters to the left of the @ symbol

First find the location of the first @ symbol, then store the local part to a new variable using the substring() method

  1. The length of the domain part is 2 to 255

Less than 2 or more than 255 characters after the @ symbol

Same thing, but set the starting point for the substring() to the right of the @ symbol so it grabs the characters from there to the end.

  1. The domain part does not include any underscore characters

Illegal underscore after the @ symbol

  1. The local part does not have any contiguous dots

There are contiguous dots before the @ sign

If you find a .. in the string, there is at least one occurance of contiguous dots

  1. The top-level domain is valid

The top-level domain is invalid

There are hundreds, but only check for .com, .org, .net, .edu, .gov, .tv, .mx, and consider anything else invalid

  1. Obtain a String from the end user, store it to a String variable.
  2. Trim away any leading or trailing whitespace, then display the length.
  3. Set a boolean flag variable and initialize it to true.
  4. Perform a series of if tests to validate each of the cases in the chart above.
  5. Display the location of the first @ symbol.
  6. If it fails any test, display the issue, then set the flag variable to false. Move on to the next test.
  7. Once all the individual tests are complete, display either Email address is valid or Email address is invalid.

This isn't a complete email address validator algorithm, so we have to be careful not to throw things at it that it's not ready to handle. Use these for your test data: avi8tor@gmal.com admissions@towon@edu info@umd\.edu jpuerta@cico.mx rtchouda@cocast_bus.net Mary.Poppins@diney.mx

Sample Input/Output for Valid Email Address

Enter an email address: avi8tor@gmal.com Length: 17 Position of @ symbol: 7 (zero based)

Email address is valid

Sample input/Output for Invalid Email Address

Enter an email address: victor.atiyeh@gov.ov Length: 20 Position of @ symbol: 13 (zero based) Email address is not valid

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!