redarrow Posted April 11, 2009 Share Posted April 11, 2009 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 More sharing options...
redarrow Posted April 11, 2009 Author Share Posted April 11, 2009 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/153618-solved-function-validation-advise/#findComment-807230 Share on other sites More sharing options...
redarrow Posted April 11, 2009 Author Share Posted April 11, 2009 <?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"; } } ?> Link to comment https://forums.phpfreaks.com/topic/153618-solved-function-validation-advise/#findComment-807239 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.