please help dear experts on how to test string especially in username for example wheter it contains special charater and will return invalid!
please help...TIA
					please help...TIA
$username = 'frank!anderson';
$pos = strpos($username, "!");
if ($pos == -1)
{
   print 'dont put ! in your usernames you silly person';
}
else
{
   print 'everything is super cool and what not';
}
split('[/.-]', $date);
$string = '#richa@rd';
preg_match('/!@#$%^&*()/','$string');
$string = 'richard';
preg_match('/chard/','$string');
$username = 'frank!anderson';
$pos = strpos($username, "!");
if ($pos == -1)
{
   print 'dont put ! in your usernames you silly person';
}
else
{
   print 'everything is super cool and what not';
}
$string = 'adsf@ASDF!fdsa#FDSA%';
$lookfor[0] = '!'
$lookfor[1] = '@'
$lookfor[2] = '#'
$lookfor[3] = '%'
$i = 0;
while ($i < 4)
{
   $var = strpos($string, $lookfor[$i]);
   if ($var != -1)
   {
      echo 'passed test for $lookfor[$i]';
   }else
   {
       echo 'silly person none of those silly charcters';
   }
}
preg_match('/[\s|\n|\t|*|@|&]/', $anyVariable);
$forbid = array(' ','--', '-', '"','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','.','/','*','+','~','`','=');
    $i = 0;
    while ($i < 37) {
        $var = strpos($userID, $forbid[$i]);
        if (!empty($var)) {
            $var++;
            echo "Position " . $var . " forbidden character.<br><font color='#FF0000'>Character detected is <strong>'" . $forbid[$i] . "'</strong></font><br>";
            echo "<p align='left'><h2><font color='red'>Oops! Only Letters and Numbers are allowed on the User ID portion.</font></h2><br><br>Please <a href='javascript:onClick=history.go(-1)' class='divProfile'>» GO BACK «</a> and remove any spaces and special characters.</p>";
            exit();
        }
       
        $i++;
}
if (htmlspecialchars($string) != $string) {
//it contains special chars.
}
Comment