REG-EXPR: Allowing limited number of special chars in usernames

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I dont know that much aboput regular expressions and just want to know how to 
find out the number of special (non alphanumeric) characters in a string or how to match a string that contains less than 3 special chars.

urrently im using a function

function valid_username($string) {
   if(strlen($string)<=16&&strlen($string)>5) {
      return(preg_match('/^[ -~äöüßÄÖÜ]+$/',$string));
   } else {
      return FALSE;
   }
}

This allows usernames of 6 to 16 length containing many special chars and German "Umlaute".
But this also allows usernames like "=)/(&%$" what should not be.

So how to limit the number of special chars? This function should just return fals if number of special chars > X

Greets,

Holger Sunke

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux