Re: Re: REG-EXPR: Allowing limited number of spe cial chars in usernames
| From: | Holger Sunke | Date: | Thu, 16 Mar 2006 12:54:29 +0000 |
| Subject: | Re: Re: REG-EXPR: Allowing limited number of spe cial chars in usernames | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-232024@lists.php.net to get a copy of this message | ||
Yes thank you,
that's all I need!
> -----Ursprüngliche Nachricht-----
> Von: Rafael <rsalazar@innox.com.mx>
> Gesendet: 16.03.06 07:34:15
> An: php-general@lists.php.net
> Betreff: [PHP] Re: REG-EXPR: Allowing limited number of special chars in usernames
> Holger Sunke wrote:
> > 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.
>
> I don't really understand what you need, but...
> - how to find out the number of special (non alphanumeric) characters
> $alpha = '[a-z0-9]';
> $special_chars = preg_replace("/$alpha+/Xi", '', $string);
> * this would replace any alpha-numeric char by... nothing, leaving
> the "special chars" only, and strlen() will give you how many are
> * beware that you're saying *anything* other than alpha-numeric chars
>
> - how to match a string that contains less than 3 special chars
> * as I said above, strlen() will give you the number of these chars:
> $num_special_chars = strlen($special_chars);
>
> > preg_match('/^[ -~äöüßÄÖÜ]+$/',$string)
>
> will return TRUE if $string consists enterily of the chars between the
> square-brackets.
>
> I hope this helped a little.
>