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.
 
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.
 
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?
 
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.
 
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!
 
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?
 
Top Bottom