REG-EXPR: Allowing limited number of special chars in usernames
| From: | Holger Sunke | Date: | Wed, 15 Mar 2006 15:20:45 +0000 |
| Subject: | REG-EXPR: Allowing limited number of special chars in usernames | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-231948@lists.php.net to get a copy of this message | ||
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