I using script PHP <?php include("db.php"); $email = strip_tags(trim($_REQUEST['emailUsername'])); $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"; if (!eregi($pattern, $email)) { echo "Ensure that your email address is valid."; die(); } // Query database to check if the username is available $query = "select * from login_recruiters where username = '".$email."' "; $result = mysql_query($query); $available = mysql_num_rows($result); if($available) { echo $email." aleady registered with us."; die(); } ?> PHP: how can I 'return false' when validation failed
ajax is asynchronous - which means it's going to be event driven. it does not return true/false. you should always return false instead to stop the event and based upon the outcome on the ajax, your xmlhttp.onreadystatechange callback can either output an error or post the form properly
<script type="text/javascript"> <!-- function validate_form ( ) { valid = true; if ( document.contact_form.contact_name.value == "" ) { alert ( "Please fill in the 'Your Name' box." ); valid = false; } return valid; } //--> </script>