01.06.2013, 13:41
i made a function that checks if every character matches an array which contains valid symbols.
then you can use
EDIT: the guy above me made more simple one
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;
}
?>
PHP код:
<?php
if(IsNameValid($_POST['thename']))
{
//pass
}
else
{
//invalid character found!
}
?>