2005 Challenge Problem #4   (Spam Helper)


You have just been hired by the marketing department of a company that does all of its advertising by bombarding
millions of helpless computer users with unsolicited e-mail. As a proud member of the Society for the Proliferation
of Antagonizing Messages
(S.P.A.M.), you are thrilled with your job. Your first assignment is to help the company
compile an even larger list of e-mail addresses. Other programmers have already written code that scans Web pages
and extracts strings of characters. You are required to write a Java method that takes one such string as input and
returns true if the string is a valid e-mail address and false otherwise. This is explained further below.

public static boolean isValidEmail(String test)
{
    // fill in here
}


Define an eName to be a sequence of one or more characters, each of which is either a lowercase letter, an uppercase letter,
or a digit (0 ... 9). A valid e-mail address consists of one or more eNames separated by periods, followed by the @ character,
followed by two or more eNames separated by periods (no spaces anywhere). (For the purpose of this question, any other
characters that are usually allowed in e-mail addresses are excluded.)

Here are some example strings and the value your method should return for each:

person@hopper.mta.ca   →   true
mE.2@yOU.3   →   true
DiL@bErT.com.   →   false   (trailing period not allowed)
first.last@net   →   false   (must have more than one eName after @)
.me@gmail.gee   →   false   (leading period not allowed)
me..you@jotmail.org   →   false   (consecutive periods not allowed)
i.J.k@W.X.y.z   →   true
john@DOE@gmail.com   →   false   (only one @ character allowed)
surfing.safari.info   →   false   (must have at least one @ character)
bill.@gates.tv   →   false   (substring before @ not valid)
warren@.buffett.money   →   false   (substring after @ not valid)