• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Username validation regex

#1
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.
 
#7
Oh bugger! I was only testing the user entry part where he defines his desired userid and at that point it was being accepted... i.e. when you tab to the next field - it wasn't being rejected or stripped of white space at that point.
OK so in which case my original regex wih a slight mod will be fine with a space after the 9 as follows (as I don't want to allow the underscore which \w permits): ^[a-zA-Z0-9 ]+$

Thanks Mike.
 

3c

Active member
#8
I must be missing something. I had a user that tried to sign up using the same name she uses on facebook but it wouldn't let her. There is no way it was already taken. Evidently it wouldn't let her use a space.

Is the string that is already in the matched expression not suitable for allowing spaces?

What exactly needs to be in that field to allow spaces?
 

Brogan

XenForo moderator
Staff member
#9
Spaces are allowed by default.
What do you have in the field?

What was the error the user received?
 

Brogan

XenForo moderator
Staff member
#11
That doesn't permit spaces to be used.
Unless you want to specifically block some characters, just clear the regex field and leave it blank.
 

3c

Active member
#17
I must need more coffee...took me a minute to see the difference! LOL....

thanks much Mike!

wow Brogan....I haven't seen you get ninja'd very often around here!
 
#20
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?