Validating an e-mail address using regex
<p>I am trying to validate e-mail addresses on my website and I have been trying to code up a demo of how e-mail validation would work with JavaScript. What I am trying to do is pass in the value of the e-mail address entered by the user to the validateEmail function and then print out 'valid' or 'invalid' in the div with the id 'result'. Because I am relatively new to JavaScript, I am not sure how to accomplish this and was wondering it if someone could show me an example of how to do this?</p>

<pre><code>&lt;head&gt;
&lt;title&gt;Practice&lt;/title&gt;

&lt;script type="text/javascript"&gt;
function validateEmail(email) { 
    var re = /^(([^&lt;&gt;()[\]\\.,;:\s@\"]+(\.[^&lt;&gt;()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
} 
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form action="post" method="practice.php"&gt;
        e-mail: &lt;input id="email" type="text" onblur="validateEmail(execute(document.getElementById('email').value))" /&gt;
        &lt;div id="result"&gt;&lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
</code></pre>
