1. 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

Discussion in 'XenForo Questions and Support' started by tafreehm, May 10, 2012.

  1. tafreehm

    tafreehm Well-Known Member

    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 ?

    Glockie likes this.
  2. Nasr

    Nasr Well-Known Member

  3. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Glockie likes this.
  4. DSF

    DSF Well-Known Member

    Don't forget the ä, ü, ö, é, â etc.
    Named as 'Müller' will never write 'Mueller'
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    DSF likes this.
  6. tafreehm

    tafreehm Well-Known Member

    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

  7. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    This regex allows any order.

    Here is the same regex but including _ and -:

    ^[a-zA-Z0-9 _\-]+$
    So overall this regex allows a-z, 0-9, space, underscore, and hyphen... in any order.
    maszd, Glockie, semprot and 1 other person like this.
  8. tafreehm

    tafreehm Well-Known Member

    Thanks Jake, I didn't want to use Space in username. SO I guess I just use following code.
    maszd likes this.
  9. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    tafreehm likes this.
  10. RoldanLT

    RoldanLT Well-Known Member

    To allow spaces, underscore and hyphen?
    or this?
    Yonda likes this.
  11. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    The second one.
    RoldanLT likes this.
  12. The Forum Heroes

    The Forum Heroes Well-Known Member

    Letters only, no numbers would be ^[a-zA-Z]+$ ?
  13. Mike

    Mike XenForo Developer Staff Member

    The Forum Heroes likes this.
  14. Glockie

    Glockie Well-Known Member

    Interesting thread, sorry to bump it...
    I have set
    ^[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 ;)
  15. Brogan

    Brogan XenForo Moderator Staff Member

    Add a , to the matched characters.
  16. Glockie

    Glockie Well-Known Member

    Oh, it's that easy?
    righto - tanks for the information. :)
  17. dethfire

    dethfire Well-Known Member

    I need this but to require a letter for the first character. thanks!
  18. Mike

    Mike XenForo Developer Staff Member

    ^[a-zA-Z][a-zA-Z0-9 _\-]*$
    maszd and dethfire like this.

Share This Page