View Single Post
Old 07-27-2008, 06:29 PM   #1 (permalink)
Oilik
The Wanderer
 
Join Date: Jul 2008
Posts: 6
Thanks: 1
Oilik is on a distinguished road
Default Example: Check Usernames

This is a simple function I made to check if a string is a valid username or not. If it has illegal characters not specified, it'll return false/nothing, and if it's valid it'll return true/1.

PHP Code:
<?php
function isValid($string){
    
$string str_replace("_","",$string);
    
$string str_replace(" ","",$string);
    
$string str_replace(".","",$string);
    
$string str_replace("-","",$string);
        if(
ctype_alnum($string)){
            return 
true;
        }else{
            return 
false;
        }
}
?>
This is easier to remember than preg_replace for me :(
I've never quite understood that function...
Oilik is offline  
Reply With Quote