Jump to content

can't find the error


vang163

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.