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

XF 1.4 Username Regex Assistance

Discussion in 'Troubleshooting and Problems' started by Zelkova, Jun 2, 2015.

  1. Zelkova

    Zelkova Member

    Hello Xenforo Community!

    I am trying to allow only alpha numeric + Hangul usernames on my site but I am not having any luck.

    I am currently using the assistance of this thread to only allow alpha numeric
    https://xenforo.com/community/threads/username-validation-regex.24291/

    However upon trying to modify it to allow Hangul I am having a bit of trouble.

    From what I understand \p{Hangul} should allow all Hangul characters.

    How would I add it to my current expression? ^[a-zA-Z0-9]*$
     
  2. Mike

    Mike XenForo Developer Staff Member

    If that works, then this should do it:

    ^(\p{Hangul}|[a-zA-Z0-9])+$
     
  3. Zelkova

    Zelkova Member

    Unfortunately this solution does not work for me. It still refuses Hangul characters.
     
  4. Mike

    Mike XenForo Developer Staff Member

    The regex used doesn't actually appear to be matching in Unicode-aware mode, so unfortunately that \p{...} sequence won't actually match. It would require a code change, and it's possible this could adjust how the regex matches (particularly for matching byte patterns outside basic ASCII) so changing it in the core runs the risk of backwards compatibility breaks.

    The only alternative I can see currently relates to matching the UTF-8 pattern for the characters or enforcing it via moderation.
     
  5. Zelkova

    Zelkova Member

    I did some digging and I believe that these are the UTF-8 ranges for Hangul

    u3130-u318F and uAC00-uD7AF

    Would you mind assisting me with somehow getting these set up in regex?
     
  6. Mike

    Mike XenForo Developer Staff Member

    I'm not 100% sure this is correct, but I've converted those ranges to UTF-8 and then done hex range matching and have come up with...

    Code:
    ^([a-zA-Z0-9]|\xE3(\x84[\xB0-\xFF]|\x85.|\x86[\x00-\x8F])|\xEA(\xB0[\x80-\xFF]|[\xB1-\xFF].|\x9E[\xAF-\xFF])|[\xEB-\xEC]..|\xED([\x00-\x9D].|\x9E[\x00-\xAF]))+$
     
    Zelkova likes this.
  7. Zelkova

    Zelkova Member

    THATS IT! Thank you so much!
     

Share This Page