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

XF 1.1 Reg Exp for USernames

tafreehm

Well-known member
#1
Hello,
I am in process of converting my forum from vb to xf. I had no restriction for username before. But Now I dun wanna allow any special characters in username other than few obvious ones like ( _ - .)

How can i do that ?

Also, any action to prevent this in future would also be effective on already existed username with all those funny characters in it ?

Thanks
 

tafreehm

Well-known member
#6
That regex is for excluding a-z and 0-9. If you want to allow only those characters then it is:

Code:
^[a-zA-Z0-9]+$
That will allow only a-z and 0-9 characters. No punctuation or spaces allowed. If you want spaces then it's:

Code:
^[a-zA-Z0-9 ]+$
What if they wanna put numbers before letter or mix them up.. is it still gonna work.. How can i add following characters as well?
_ underscore
- hyphen

?
 

Jake Bunce

XenForo moderator
Staff member
#7
What if they wanna put numbers before letter or mix them up.. is it still gonna work.. How can i add following characters as well?
_ underscore
- hyphen

?
This regex allows any order.

Here is the same regex but including _ and -:

Code:
^[a-zA-Z0-9 _\-]+$
So overall this regex allows a-z, 0-9, space, underscore, and hyphen... in any order.
 

tafreehm

Well-known member
#8
This regex allows any order.

Here is the same regex but including _ and -:

Code:
^[a-zA-Z0-9 _\-]+$
So overall this regex allows a-z, 0-9, space, underscore, and hyphen... in any order.
Thanks Jake, I didn't want to use Space in username. SO I guess I just use following code.
Code:
^[a-zA-Z0-9_\-]+$
 

Glockie

Well-known member
#14
Interesting thread, sorry to bump it...
I have set
Code:
^[a-zA-Z0-9 _\-]+$
To yield results on age ranges, how can I allow commas so a user can type say for example;
30-40, 40-50

Many thanks ;)