Checking for invalid symbols? (PHP)
#5

Quote:
Originally Posted by kirollos
Посмотреть сообщение
i made a function that checks if every character matches an array which contains valid symbols.

PHP код:
<?php
function IsNameValid($str)
{
    
$valid = 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',
    
'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',
    
'(',
    
')',
    
'_',
    
'[',
    
']',
    
'.',
    );
    
$count 0;
    for(
$a 0$a strlen($str); $a++)
    {
        for(
$b 0$b sizeof($valid); $b++)
        {
            if(
$str[$a] == $valid[$b]) break;
            
$count ++;
        }
        
        if(
$count == sizeof($valid)) return 0;
        else {
        
$count 0;
        continue;
        }
    }
    return 
1;
}
?>
then you can use

PHP код:
<?php
if(IsNameValid($_POST['thename']))
{
    
//pass
}
else
{
    
//invalid character found!
}
?>
EDIT: the guy above me made more simple one
Why would you take the time to do that? You can use regular expressions straight from PHP.
Reply


Messages In This Thread
Checking for invalid symbols? (PHP) - by .Mento - 01.06.2013, 13:22
Re: Checking for invalid symbols? (PHP) - by nielsbon1 - 01.06.2013, 13:34
Re: Checking for invalid symbols? (PHP) - by Kirollos - 01.06.2013, 13:41
Re: Checking for invalid symbols? (PHP) - by .Mento - 01.06.2013, 13:49
Re: Checking for invalid symbols? (PHP) - by playbox12 - 01.06.2013, 13:57
Re: Checking for invalid symbols? (PHP) - by Kirollos - 01.06.2013, 14:37

Forum Jump:


Users browsing this thread: 1 Guest(s)