Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

why cann't use Asian characters as a user' name ? Is there a solution ?

longnightlongnight New
edited November 2010 in Vanilla 2.0 - 2.8
why cann't use Asian characters to register a user name , such like "李国蛋" "张学友"or "わかった" ?

I hope my users can use Characters which their are more familiar than Latin words .

Is there a solution ?

My website is using UTF-8 database, welcome to visit:

Vanilla 2 .



  • i also want to know....
  • i also want to know....
    I think it's a big important problem !

  • let it up ! need sb help ...
  • yu_tangyu_tang New
    edited December 2010
    3 steps.

    in vanilla\library\core\functions.validation.php
    Search ValidateUsername() function and change regexp pattern from
    '/^([一-龠]|[ぁ-ん]|[ァ-ヴー]|[ a-zA-Z0-9_\-]|[ a-zA-Z0-9_―]){3,20}?$/u'
    Above pattern is for Japanese. So you should be wrote difference depending on your language.

    Now, you can use non-ascii characters for username.

    If you change username to non-ascii characters in profile, you may encounter 404 error after save and redirect.
    in vanilla\applications\dashboard\controllers\class.profilecontroller.php
    Search Edit() function and change redirect code from
    $this->RedirectUrl = Url('/profile/'.Gdn_Format::Url($User->Name));
    $this->RedirectUrl = Url('/profile/'.$User->UserID.'/'.Gdn_Format::Url($User->Name));

    2010-12-16: another solution found.
    $User = $this->SQL->Where('u.Name', $Username)->Get()->FirstRow();
    $User = $this->SQL->Where('u.Name', urldecode($Username))->Get()->FirstRow();

    I edited this and found 中文用户名解决方案 - Vanilla Forums. lol

    Anyway, now 404 error has gone.

    In default, Vanilla count letters as ascii. Thus a non-ascii character is counted 2 or 3 length in UTF-8.
    That causes a problem about 20 chars max for username. You get over limit error with 10 or 7 chars non-ascii username.
    Once again in vanilla\library\core\functions.validation.php
    Search ValidateLength() function and change code from
    $Diff = strlen($Value) - $Field->Length;
    $Diff = mb_strlen($Value, 'utf-8') - $Field->Length;

    That's it.

    One thing, I am an amateur in PHP. Actually I rent PHP dictionary from library yesterday because I know nothing.
    So I guess if Vanilla core developers allows only ascii for username, maybe they have the reasons. Don't trust this hack.
  • @yu_tang Thanks a lot !
    I'll try your method soon !
    But, change from
    '/^([一-龠]|[ぁ-ん]|[ァ-ヴー]|[ a-zA-Z0-9_\-]|[ a-zA-Z0-9_―]){3,20}?$/u'

    How about Chinese,what should I apply ? 中文.
    or What's these code's name ? I'll search them to replace.
  • yu_tangyu_tang New
    edited December 2010
    @longnight You're welcome!
    How about Chinese,what should I apply ? 中文.
    Google pointed out...
    regex - PHP -Multibyte regular expression to remove all but chinese characters...please help - Stack Overflow

    so, maybe...


    Sorry, I didn't test it. It's just a thought.

    btw, non-ascii user name breaks @ link function in comments.
    I realized just now. I think we need more help or insensitivity.
  • oops....


    both these two hack can't use asian words ......

    change to
    '/^([一-龠]|[ぁ-ん]|[ァ-ヴー]|[ a-zA-Z0-9_\-]|[ a-zA-Z0-9_―]){3,20}?$/u'
    resules in any words(Asian and Latin ) to register fail .

    change to
    This time it still can't use Asian Characters to register , but Latins word was allowed .
  • Ok, another shot.
    try this.
  • longnightlongnight New
    edited December 2010中文用户名解决方案


    this line worked. anyway ,thanks for your kind heart ,welcome to visit my forum:

    There still be some small promblems ;)
  • Congrats! @longnight
    There still be some small promblems ;)
    For functioning @mentions links with asian chars username, you'd better to check this.

    $Mixed = preg_replace( '/(^|[\s,\.])@(\w{1,20})\b/i', //{3,20} '\1'.Anchor('@\2', '/profile/\\2'),

    Yes, another regexp pattern there. Good luck!
  • @yu_tang @longnight also there's #topic bug. and some small bugs in mobile mode.
    alt attribute of user's head image.
    modify regexp pattern or use urldecode() function will work.

    our forum is invitation register only.
  • It's a good thing you guys tested this. The devs should fix their code to make this possible out of the box. Applications like this one always support UTF8 "in theory", but not always in practice. ;)
Sign In or Register to comment.