validate email with regex jquery
<p>referring to this issue:</p>

<p><a href="http://stackoverflow.com/questions/9571483/how-can-i-set-a-minimum-length-for-a-field-with-jquery">how can I set a minimum length for a field with jquery?</a></p>

<pre><code>&lt;form id="new_invitation" class="new_invitation" method="post" data-remote="true" action="/invitations" accept-charset="UTF-8"&gt;
&lt;div id="invitation_form_recipients"&gt; 
&lt;input type="text" value="" name="invitation[recipients][]" id="invitation_recipients_0"&gt;&lt;br&gt;
&lt;input type="text" value="" name="invitation[recipients][]" id="invitation_recipients_1"&gt;&lt;br&gt;
&lt;input type="text" value="" name="invitation[recipients][]" id="invitation_recipients_2"&gt;&lt;br&gt;
&lt;input type="text" value="" name="invitation[recipients][]" id="invitation_recipients_3"&gt;&lt;br&gt;
&lt;/div&gt;
&lt;input type="submit" value="Send invitation" name="commit"&gt;
&lt;/form&gt;
</code></pre>

<p>Code for set a minimum length for a field with jquery?</p>

<pre><code>$('#new_invitation').submit(function(event) {
if ($('#invitation_form_recipients input').filter(function() {
    return $(this).val();
}).length == 0) {
    // all the fields are empty
    // show error message here

    // this blocks the form from submitting
    event.preventDefault();
}

});
</code></pre>

<p><strong>How can I validate that every field input have a valid email address with jquery? in the above code?</strong></p>

<p>Thank you!</p>

<h2> The Solution! </h2>

<pre><code>$('#new_invitation').submit(function(e)  {
 $('#invitation_form_recipients input').each(function(e) {
   email_address = $(this);
   email_regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i;
   if(!email_regex.test(email_address.val())){ alert('this is not valid email'); e.preventDefault(); return false;  }
 });    
});
</code></pre>
