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

XF 1.4 Expression for a-z, 0-9 usernames only

Discussion in 'XenForo Questions and Support' started by CollinL, Nov 5, 2014.

  1. CollinL

    CollinL Member

    Hi,

    I want to use a "Match Regular Expression" in my user registration options to only allow a-z, A-Z and 0-9 usernames (no spaces, dots or any of that stuff). I did a bit of research and I think I've got the answer, but I am seeking verification as I don't know what I'm doing.

    Is this what I would need?: ^[A-Za-z0-9]

    Any help would be appreciated. Thanks!
     
  2. EQnoble

    EQnoble Well-Known Member

    this should work for you
    #[a-z0-9]#i
     
    Last edited: Nov 5, 2014
  3. CollinL

    CollinL Member

    Thank you for your input, but that code seems to disallow usernames I would want to be allowed (example: abc123)

    I also tested the regex in the OP and that seemed to allow all usernames.
     
  4. EQnoble

    EQnoble Well-Known Member

    sorry, typo... (fixed)
    #[a-z0-9]#i
    the i belongs after the delimiter
     
    Last edited: Nov 5, 2014
  5. Mike

    Mike XenForo Developer Staff Member

    This example should specifically be:

    ^[a-z0-9]+$

    It doesn't need the delimiters and it's case insensitive as is.
     
    maszd likes this.
  6. CollinL

    CollinL Member

    Thank you very much. Can you please also tell me what code I would want to use to follow original specifications + allow underscores?
     
  7. CollinL

    CollinL Member

    Oops, never mind. Looks like I'd just need to throw an underscore after the 9.
     

Share This Page