PDA

View Full Version : Help with usernames, PCRE-type regular expressions


kpmedia
01-09-2011, 10:14 PM
Need a little help here, trying to limit usernames for new registrations.

I can see this in admincp vB options, but it's either too much filtering or not enough:
You may require the username to match a PCRE-type regular expression.
(Do not start or end the expression with an escape character)
Examples:
^[A-Z]+$ - Characters from A-Z only
^[A-Z ]+$ - Characters from A-Z including space
^[A-Z0-9 ]+$ - Alphanumeric characters including space
^((?!&#\d+;)[\x20-\x7E])+$ - ASCII characters from 32-127
See PHP.net for more information on regular expressions.I want A-Z, 0-9, periods, underscore, spaces and hyphens --- and that's it.
Any help on what this syntax would be?


Also...

And if you know how...
Preferably no "repeat" periods/underscore/hyphen/spaces.
i.e., "--BESTUSEREVER-- ___ -- 123"
Better yet, limit to two total periods, underscores, hyphens, spaces
I don't want any more users trying to use screwball usernames full of ASCII.
Or even overusing what is allowable non-letter/non-number.

Thanks.

Lynne
01-09-2011, 10:24 PM
Um, maybe:

^[A-Z0-9\._- ]+$

Really not sure exactly. I just added & and # to my list of illegal usernames.

kpmedia
01-23-2011, 09:57 PM
I just added & and # to my list of illegal usernames.
Brilliant idea. :)

I chronicled my findings on this issue at http://www.digitalFAQ.com/forum/showthread.php/prevent-stupid-ascii-2823.html
And yours was the one that worked best.

Thanks.