Jump to content

[SOLVED] function validation advise


redarrow

Recommended Posts

would this be better or make no difference.

<?php
$test="123456634<5678";

if(letters_numbers(trim($test))){

echo	letters_numbers(trim($test));

}
?>

 

I was going to use this validation code, with the functions so , i didn't have to keep creating the same preg_match validation code.

 

 

I thort, all i do is echo the function out, next to the form input to show there a error.

 

what you think please.

 



<?php
function letters_numbers($letters_numbers){

	if(!preg_match("/^[0-9a-z]{0,200}$/i",$letters_numbers)){

		$warning="<div style='color: #FF0000;'>*</div>";

		return($warning);
	}
}

function numbers($numbers){

	if(!preg_match("/^[0-9]{0-200}$/",$numbers)){

		$warning="<div style='color: #FF0000;'>*</div>";

		return($warning);
	}
}

function yes_no($yes_no){

	if(!preg_match("/(yes|no)/",$yes_no)){

			$warning="<div style='color: #FF0000;'>*</div>";

		return($warning);

	}


}



$test="123456634<5678";

echo letters_numbers(trim($test))


?>

Link to comment
https://forums.phpfreaks.com/topic/153618-solved-function-validation-advise/
Share on other sites

solved





<?php
function letters_numbers($letters_numbers){

	if(!preg_match("/^[0-9a-z]{0,200}$/i",$letters_numbers)){

		$warning="<div style='color: #FF0000;'>*</div>";

		return($warning);
	}
}

function numbers($numbers){

	if(!preg_match("/^[0-9]{0-200}$/",$numbers)){

		$warning="<div style='color: #FF0000;'>*</div>";

		return($warning);
	}
}

function yes_no($yes_no){

	if(!preg_match("/(yes|no)/",$yes_no)){

			$warning="<div style='color: #FF0000;'>*</div>";

		return($warning);

	}


}



	$test="12b34566a345678";

if(letters_numbers(trim($test))){

echo	letters_numbers(trim($test));

}else{

	echo "No error";

}
	$test="123456a6345678";

if(numbers(trim($test))){

echo	numbers(trim($test));

}else{

	echo "No error";

}


		$test="no";

if(yes_no(trim($test))){

echo	yes_no(trim($test));

}else{

	echo "No error";
}

?>

 



<?php
function letters_numbers($letters_numbers){

	if(!preg_match("/^[0-9a-z]{0,200}$/i",$letters_numbers)){

		$warning="<div style='color: #FF0000;'>*</div>";

		return($warning);
	}
}

function numbers($numbers){

	if(!preg_match("/^[0-9]{0,200}$/",$numbers)){

		$warning="<div style='color: #FF0000;'>*</div>";

		return($warning);
	}
}

function yes_no($yes_no){

	if(!preg_match("/(yes|no)/",$yes_no)){

			$warning="<div style='color: #FF0000;'>*</div>";

		return($warning);

	}


}



$test="12b34566a345678";

if(letters_numbers(trim($test))){

echo	letters_numbers(trim($test));

}else{

$warning[]=TRUE;

}
	$test="1234566345678";

if(numbers(trim($test))){

echo	numbers(trim($test));

}else{

	$warning[]=TRUE;

}


		$test="no";

if(yes_no(trim($test))){

echo	yes_no(trim($test));

}else{

	$warning[]=TRUE;
}


	foreach($warning as $warn){

		if($warn==TRUE){

		echo " <br><br> yeeee haaaaaaaaaaa ENTER RUBISH TO DATABASE!";

		break;

	}else{

		echo "<br><br> nooooooooo yaaaaaaaaaa";
	}
}
?>

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.