jquery filter to match php

jquery filter to match php

none of the validation plugins and jquery tools validation seem to fit my needs, so i decided to follow a tutorial and write mine from scratch.

i followed the tutorial for the jquery side from here:
http://yensdesign.com/2009/01/how-validate-forms-both-sides-using-php-jquery/

i've incorporated a php email script i had for a while instead and copied the email validation from my jquery script into php so they match. jquery and php validation both works and email sends

[php]
if(trim($_POST['email']) == '')  {$hasError = true;}
     else if (!eregi("^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$", trim($_POST['email']))) {$hasError = true;}
     else {$email = trim($_POST['email']);}

[jquery]
var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;

then i realized the email validation filters out newer, but valid addresses.. so i tried to validate it following this website:
http://www.addedbytes.com/code/email-address-validation/

[php]
$email_array = explode("@", trim($_POST['email']));
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
     if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {$hasError = true;}
     }
if(trim($_POST['email']) == '')  {$hasError = true;}
     else if (!ereg("^[^@]{1,64}@[^@]{1,255}$", trim($_POST['email']))) {$hasError = true;}
     else if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
          $domain_array = explode(".", $email_array[1]);
          for ($i = 0; $i < sizeof($domain_array); $i++) {
               if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {$hasError = true;}
          }
     }
     else {$email = trim($_POST['email']);}

the new php validation works. i've been with php longer than jquery, so i'm having problems trying to convert that into a jquery filter which i can replace the old one.. can anyone help?