07-27-2008, 05:29 PM
|
#1 (permalink)
|
|
The Wanderer
Join Date: Jul 2008
Posts: 6
Thanks: 1
|
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...
|
|
|
|