garfield

[PHP]: Verificar se string é válida

Jan 19th, 2012
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. /*
  2.     @Função: Verificar se uma string é válida
  3.     @Créditos: [iPs]SuYaNw | Garfield
  4.  
  5.  
  6.     Modos de verificação:
  7.     Modo 0: Verifica se tem caracteres inválidos,
  8.     Modo 1: Verifica se tem algum número na string.
  9. */
  10.  
  11.  
  12. function IsValidString($str, $mode)
  13. {
  14.     switch($mode)
  15.     {
  16.         case 0:
  17.         {
  18.             $MyChars = array("!","@","'","#","$","%","¨","&","*","(",")","-","_","=","+","¹","²","³","[","]","ª",
  19.                              "º","°","{","}","?","/",";",":",".",">","<",",","|","§");
  20.            
  21.             for($i = 0; $i != count($MyChars); ++$i)
  22.             {
  23.                 //echo $MyChars[$i]."<br>";
  24.                 if(!strstr($str, $MyChars[$i]))
  25.                 {
  26.                     return true;
  27.                 }
  28.             }
  29.         }
  30.         case 1:
  31.         {
  32.             for($j = 0; $j != count($str); ++$j)
  33.             {
  34.                 if(is_numeric($str[$j]))
  35.                 {
  36.                     return false;
  37.                 }
  38.             }
  39.             return true;
  40.         }
  41.     }
  42.     return false;
  43. }
  44.  
  45.  
  46.  
  47.  
  48.  
  49. #Como usar:
  50. if(IsValidString("Olá Amigos", 0))
  51. {
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment