Username validation regex

Mancunian

Member
I am looking for some help on fixing my "Username match Regular Expression".
I am currently using this:
^[a-zA-Z0-9]+$
This does not permit a space within the username.

However, I want to allow a single space within the username but not allow multiple spaces.
So
John Doe - should be valid - as should John F Doe - i.e. a space between each word.
but
John.......Doe is invalid as it has multiple intervening spaces - shown here as dots as I cannot enter white space.

Can anybody help a I am suffering from a brain freeze with regex.
 
I want to allow everything that Xenforo currently allows in username (spaces, special characters, etc.), but I want to exclude any foreign language characters other than Western European stuff like Á, È, Ö, etc. I also want to exclude any weird special characters (stuff that doesn't show up on a normal US English qwerty keyboard) so someone's username doesn't end up being something like this: ┻ (ノಠ益ಠ)ノ彡┻

I found this regex string online, but I don't think it's exactly what I need:
Code:
^[\-\.a-zA-Z0-9'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ\\ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ]*$

Any ideas?

I am not familiar with the entire range of accented latin characters, but that regex appears to explicitly name all of the allowed accented characters as well as the range of unaccented characters and numbers (a-z, 0-9). It also allows some punctuation (dash, period, single quote, backslash, but no spaces). That regex explicitly names what is allowed thereby excluding everything else.

That regex looks like what you need.
 
I think about a regex for usernames also, but it will make problems to stupid users; so i would like to have another solution like changing the name for my needs:

If someone enters "Andy King" i want the name to be "Andy-king".
Means: replace " " with "-"; lower all chars, ucase first.

Probably i need an addon doing this, but when?
Before testing if the name is ok and free to use?
 
Top Bottom