Help with AlphaNumeric checker

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
swapshop
Forum Newbie
Posts: 1
Joined: Tue Aug 09, 2005 1:44 pm

Help with AlphaNumeric checker

Post 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;
   
   
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
Post Reply