if(isset($_POST["submit"])){ $error_msg=''; if(trim($_POST["userName"])=='' || strlen(trim($_POST["userName"])) < 3 || strlen(trim($_POST["userName"])) > 20) { $error_msg.="Please enter a username between 3 to 20 characters long
"; } if(trim($_POST["password"])=='' || strlen(trim($_POST["password"])) < 4) { $error_msg.="Please enter a password at least 4 characters long
"; } if(trim($_POST["agreement"])=='') { $error_msg.="Please tick the box
"; } if(trim($_POST["emailAddress"])=='') { $error_msg.="Please enter an email
"; } else { // check if email is a valid address in this format username@domain.com if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]", $_POST["emailAddress"])) $error_msg.="Please enter a valid email address
"; } // display error message if any, if not, proceed to other processing if($error_msg=='') { // more processing }