Page 1 of 1

Help with AlphaNumeric checker

Posted: Tue Aug 09, 2005 1:46 pm
by swapshop
Hey, im trying to build an alphanumeric checker which modifys a link according to its results.. im guessing the problem is in the last function.. any help will be greatly appreciated. thank you :)

Code: Select all

<?php

$redirect = "http://www.mydomain.com/verify.php?verify=1";

function isAlphaNumeric( $str )
   {
       $originalLength = strlen( $str );
       $replacedLength = strlen( preg_replace("#[^A-Za-z0-9_]#", "", $str ) );
       return $originalLength == $replacedlength;
   }
   
function isEmail( $str )
   {
       $originalLength = strlen( $str );
       $replacedLength = strlen( preg_replace("#[^A-Za-z0-9_@.]#", "", $str ) );
       return $originalLength == $replacedlength;
   }


function isValid( $post )
	{
		if (isAlphaNumeric($_POST[$post]))
	  		{
	    		$redirect .= "&" . $post . "=true"; 
	  		}
		else
			{
				$redirect .="&" . $post . "=false";
			}
	}

	
isValid ("username");
echo $redirect;
   
   
?>

Posted: Tue Aug 09, 2005 2:12 pm
by feyd
you need to specify that $redirect in the last function is from the global space.

Your validation functions are a bit odd, I must say..