Basically i'm checking to make sure a username only contains a-z A-Z 0-9 and spaces... and it works using the following code but is there a better/cleaner/faster way of doing this
Code: Select all
<?php
$c = Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9',' ');
$t = strtolower($username);
for($i=0; $i<strlen($t); $i++)
{
$invalid = true;
for($ii=0; $ii<count($c); $ii++)
{
if(stristr(substr($t,$i,1),$c[$i]))
{
$invalid = false;
}
}
}
if($invalid)
{
$error = "your username contains invalid characters";
}
?>