I want to create a loop to reject the email addresses that start or end with an @ character, contain multiple @ characters or contain no . (dot) characters. I have a problem with the condition for contain multiple @ characters or contain no . (dot)characters. My conditions don’t run correctly. Please help me. Thank you very much.
[COLOR=#0070c0][FONT=serif]var address = "me@mock.org";[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif]var i = 0;[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif]var count = 0;[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif]var total =0;[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif]var isValidAddress = false;[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif]while (i< address.length )[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif]{[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] if (address.charAt(0) == "@" || address.charAt(address.length - 1) == "@" )[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] {[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] trace("first or last character is @. Invalid email address.");[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] break;[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] }[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] else if (address.charAt(i) != ".")[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] {[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] trace ("it doesn't contain a dot");[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] break;[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] }[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] else if (address.charAt(i) == "@" )[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] { [/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] count =1; [/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] total +=count;[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] if (total ==1) [/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] {[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] isValidAddress = true;[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] trace("Valid email address.");[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] }[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] trace("Total is " + total);[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] }[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif] i++;[/FONT][/COLOR]
[COLOR=#0070c0][FONT=serif]}[/FONT][/COLOR]