Pure javascript validation
<p>I am tiring to do valid email and required fields validation but with this function i do witch i want to do with only pure JavaScript it keep show only the required em </p>

<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
    &lt;title&gt;JS valdation&lt;/title&gt;
    &lt;script type="text/javascript"&gt;
        function validateForm() {
            var email = document.getElementById('emailaddress');
            var name = document.getElementById('username');
            var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if (email.value == "" || name.value == "") {
                document.getElementById("required").style.display = "block";
                document.getElementById("required_email").style.display = "block";
                document.getElementById("valide_email").style.display = "none";
            }
            else if(!filter.test(email.value)) {
                document.getElementById("valide_email").style.display = "block";
                document.getElementById("required").style.display = "none";
            }
            return false;
        }
    &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form name="myForm" action="" onsubmit="return validateForm();" method="post"&gt;
Email: &lt;input id="emailaddress" type="text" name="email"&gt;
&lt;input type="submit" value="Submit"&gt;
&lt;em id="valide_email" style="display:none"&gt;please enter a valid email ex:(user@user.com)&lt;/em&gt;
&lt;em id="required_email" style="display:none"&gt;this filed is required&lt;/em&gt;
First name: &lt;input id="username" type="text" name="fname"&gt;
&lt;em id="required" style="display:none"&gt;this filed is required&lt;/em&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
