Ummm...there's no such thing as "switching".
Oh, and in any case, your email test is virtually worthless. I could type in .@@@@@@....
and your code would be perfectly happy.
Email validation has been discussed in this forum dozens if not hundreds of times. Do a simple search in the forum for *good* examples.
Also, your method of telling the user about errors is really bad.
You go to all the trouble of creating an array of errors, but then you *STILL* output the errors via alert( )
one at a time!
At the very least you could do:
if(count != 0)
alert( "Please correct:\n" + error.join("\n") );
// there is NO POINT in having an else here! the return means "return right now!"
However, as many here will be happy to tell you, alert( )
is very badly out of style. Some browsers allow users to turn off ALL alerts. And likely most all browsers will do so soon.
p.s. There's also no need for your count
if ( ...something fails validation... )
error.push( "...the error message..." );
if ( error.length == 0 ) return true;
document.getElementById("somePlaceToShowErrors").innerHTML = error.join("<br/>");