how to do identify a string inside has no integer (0 - 9)? when i try to write source code for this, it make me blur... please help... thanks...
<?php function to_echo($f_input1,$f_input2,$debug){ if($debug == 1){ echo $f_input1. " => ".$f_input2."<br>"; } } $name = "lu chen"; to_echo("name",$name,1); $name1 = str_replace(" ","",$name); to_echo("name",$name1,1); $len_name1 = strlen($name1); to_echo("length name",$len_name1,1); for($a=1;$a<$len_name1+1;$a++){ $char_name = substr($name1,$a-1,1); echo "str: ".$char_name."<br>"; if(is_numeric($char_name)){ echo "contain integer!"."<br>"; } } ?> PHP: finally has done... however i had written a long code just for validation of name
If you only want to detect, not sanitize it and remove it, you can use this. $input = 'asda091283xxx'; if (preg_match('/([0-9]+)/', $input)) { echo 'You are a malicious user. Do not put numbers here.'; } else { echo 'You are a nice user. Thank you.'; } PHP: But if you want to remove it automatically, use this. <?php $input = 'asda091283xxx'; $clean_input = preg_replace('/([^0-9]+)/', '', $input); echo 'New and clean one : ', $clean_input; ?> PHP:
http://www.php.net/manual/function.strspn.php if(!strspn($input, '1234567890')) { // $input does not contain an int } Code (markup):