function doAjaxPost() {  
 // get the form values  
 var emailaddress = $('#emailaddress').val();  
 
 if( isValidEmailAddress( emailaddress) ){    

     $.ajax({  
       type: "POST",  
       url: "/projects/javascript/emailform/success.php",  
       data: "email="+emailaddress,  
       success: function(resp, status, xhr){  
         // we have the response  
         //alert("Server said:\n '" + resp + "'"); 
         $("#success").html(resp);
       },  
       error: function(e){  
         alert('Error: ' + e);  
       }  
     });   
  
 }else {
 
    alert('Please Enter a Valid Email Address')   ;

 }
}  
    
function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(emailAddress);
};

