Email Validation with JavaScript
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/46155/validate-email-address-in-javascript">Validate email address in Javascript?</a>  </p>
</blockquote>



<p>This is my first post and I have a small issue. I'm trying to validate an email address on a form, but with no luck. I found this snippet on the internet but it doesn't seem to be working. I'm using Javascript at the moment to validate it. I don't usually use JS, so any help would be appreciated.</p>

<pre><code>&lt;script type="text/javascript"&gt;
    function ValidateEmail(inputText)  
    {  
       var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;  
       if(inputText.value.match(mailformat))  
       {  
           document.forms.emailform();  
           return true;  
       }  
       else  
       {  
           alert("You have entered an invalid email address!");  
           document.forms.emailform();  
           return false;  
       }  
    }  
</code></pre>

<p></p>

<pre><code>&lt;?php
    $addemail .= '

        &lt;form method="post" action="cart2.php" name="emailform" onsubmit="return validateEmail"&gt;
        ';
    $addemail .= '
            E-mail Address: &lt;input type="text" name="email" value="'.$row6['email'].'" size="19" /&gt;&lt;input type="hidden" name="cartid" value="'.$cart.'" /&gt;';
        if ( $emailerror != '' )
            {
                $addemail .= '&lt;img src="images/email_error.png" width="16" height="16" hspace="4" alt="E-mail Error" /&gt;';
            }
        $addemail .= '
            &lt;input type="image" name="Add E-mail Address" alt="Add E-mail Address" src="images/addemail.gif" style="vertical-align:middle" /&gt;
        &lt;/form&gt;
    ';
    if ( $row6['email'] == '' )
        {
            $emailpresent = 0;
        }
    else
        {
            $emailpresent = 1;
        }
}
        $addemail .= '
                &lt;/td&gt;
            &lt;/tr&gt;
        ';
}

?&gt;
</code></pre>
