vang163 Posted July 29, 2008 Share Posted July 29, 2008 hi, i'm trying to create a common form validation script [validate.php] for validating 2 forms [form1.php, form2.php]. validate.php consists of 2 functions: function validateEmail($email, $location) { if($location == 'form1.php') { if(!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $email)) { $message[] = 'Invalid email.'; } } else if($location == 'form2.php') { if(!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $email)) { $message[] = 'Invalid email address.'; } else if(strlen($email) > 50) { $message[] = 'Email address too long.'; } } $_SESSION['MESSAGE'] = $message; session_write_close(); header("location: $location"); exit(); } function validatePWD($password, $location) { $regular_expression = '/^[a-zA-Z0-9]*$/'; if($location == 'form1.php') { if(!preg_match($regular_expression, $password)) { $message[] = 'invalid password.'; } else if(strlen($password) < { $message[] = 'invalid password.'; } } else if($location == 'form2.php') { if(!preg_match($regular_expression, $password)) { $message[] = 'No special characters allowed.'; } else if(strlen($password) < { $message[] = 'Password too short.'; } else if(strlen($password) > 50) { $message[] = 'Password too long.'; } } $_SESSION['MESSAGE'] = $message; session_write_close(); header("location: $location"); exit(); } } The first function [validate email] works fine, i can see the error message when i test. But when it comes to validate password, i try to make error but could not see any error message appear! Have i miss out something? Link to comment https://forums.phpfreaks.com/topic/117119-cant-find-the-error/ Share on other sites More sharing options...
samshel Posted July 29, 2008 Share Posted July 29, 2008 can be following cases... 1) may be $location is not passed to the function. 2) your regular expression does not catch the error. 3) there is no error.. Link to comment https://forums.phpfreaks.com/topic/117119-cant-find-the-error/#findComment-602399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.