0) { if(!ereg('^[a-z A-Z]+$', $name)){ $error['name'] = "Your name contains invalid characters. Only letters are allowed! "; // invalid characters } } else { $error['name'] = "Please enter your name!"; // the name field was left blank } //validate phone number if (strlen(trim($phone)) > 0) { if(!ereg('^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$', $phone)){ // $error['phone'] = "Your phone number is not valid!"; } } //validate email if (strlen(trim($email)) > 0) { if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ $error['email'] = "Your email address is not valid!"; } } else { $error['email'] = "Please enter your email address!"; } // Check the message if (!strlen(trim($message)) > 0) { $error['message'] = "Please enter your message!"; } // // We are finished validating the form. Now, let's see if there were any errors. // If there are no errors, we proceed. If there are errors, we will print // them to the screen and highlight the fields in the form // if (empty($error)) { // There were no errors! $msg = "Congrats, $name! There were no errors in the form!"; } else { // There were errors, let's set the styles for the fields $error_msg = "