Sorry, I was thinking indexOf returned false if the string was not found. Disregard that statement

I should have said,
email.indexOf("@") would
always evalute to true (unless it's the first character in which it would be 0 and this, false). If the string is not found, indexOf returns -1, which still evaluates to true.
Quote:
|
Isn't the evaluation more like: If '@' is the last character?
|
This is the main problem. The "OR" (||) operator is splitting the condition into two bits, it doesn't "extend" one into the other. Your condition is really saying (in most cases, excluding the '@' being first character like stated above) "If true, or if '.' is the last character" when you want it to say "If '@' is the last character, or if '.' is the last character".
With that said, I think the problem lies within the numbers. The
length property holds the length of the string (obviously), but the
indexOf() method returns the index of the string. The indexes start at zero, not one. For example, in the string "123", "1" would be in spot 0, "2" in spot 1 etc. So you need to alter it a bit further and subtract one from the length (or alternatively, add one to the indexOf):
Code:
else if ((email.indexOf("@") == email.length-1 || email.lastIndexOf(".")) == email.length-1) {