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:
| Invalid length | Proceed with the rest of the tests ONLY if the length is valid. Otherwise, display the error and end. |
| 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. |
| 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 |
| 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. |
| Illegal underscore after the @ symbol |
|
| There are contiguous dots before the @ sign | If you find a .. in the string, there is at least one occurance of contiguous dots |
| 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 |
- Obtain a String from the end user, store it to a String variable.
- Trim away any leading or trailing whitespace, then display the length.
- Set a boolean flag variable and initialize it to true.
- Perform a series of if tests to validate each of the cases in the chart above.
- Display the location of the first @ symbol.
- If it fails any test, display the issue, then set the flag variable to false. Move on to the next test.
- 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started