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

XF 1.4 How to disable numbers usernames

Discussion in 'XenForo Questions and Support' started by AscalonCZ, Dec 14, 2014.

  1. AscalonCZ

    AscalonCZ Member

    Hello guys, can you please help me with username registration. I want disable registration users with only numbers in username like 12547951. If they have for example Dan45, Asterix77 it is OK, just clear numbers registration.
  2. Mike

    Mike XenForo Developer Staff Member

    You just need to set the username regex to match one non-number character:

  3. AndyB

    AndyB Well-Known Member

    This is what I use:


    This allows all alphabet characters and numbers, but it also allows only a number. How would I use what I have and disallow just a number?
  4. Brogan

    Brogan XenForo Moderator Staff Member

    If you mean to prevent any numeric characters, use ^[a-z]+$
  5. AndyB

    AndyB Well-Known Member

    I mean the following:



    AscalonCZ likes this.
  6. AscalonCZ

    AscalonCZ Member

    Andy B version is correct, i want allow numbers in usernames, but not ONLY numbers.
  7. AscalonCZ

    AscalonCZ Member

    Is there any option? :)
  8. Jashugan

    Jashugan Member

    I'd also like to know this please. Since obviously no real user will just be using numbers.
  9. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Admin CP -> Home -> Options -> User Registration -> User Name Match Regular Expression

    Alpha only:

    Alpha+space only:

    ^[a-zA-Z ]+$
    Alphanumeric only:

    Alphanumeric+space only:

    ^[a-zA-Z0-9 ]+$
    Alphanumeric+space+underscore only:

    ^[a-zA-Z0-9 _]+$
    Alphanumeric+space+underscore+dash only:

    ^[a-zA-Z0-9 _\-]+$
    Donny, Infopro and Jashugan like this.
  10. Jashugan

    Jashugan Member

    Cheers for that, although I don't think those would do what we were looking for exactly.

    I think the OP was looking to allow letters and numbers, but disallow if ONLY numbers.
  11. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Mike's regex should work for that, though it doesn't explicitly say what the character range is, only that one must not be a number.

    This is more explicit... this is alphanumeric only with at least one alpha somewhere:

    Or you may want to allow spaces also:

    ^[a-zA-Z0-9 ]*[a-zA-Z][a-zA-Z0-9 ]*$
    maszd, Jashugan, AndyB and 1 other person like this.
  12. AscalonCZ

    AscalonCZ Member

    Thank you Jake, this is what I am looking for, excellent work. (y)
  13. ŽivaAkcija

    ŽivaAkcija Well-Known Member

    not work on my board, i test it on caps lock and not works?
  14. ŽivaAkcija

    ŽivaAkcija Well-Known Member

    Hi i use PHP 7.10 and mariadatabase i try all codes above but none of them not works any help?
    Got big problems with users who use caps lock in nick names.
  15. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Hmm. My mistake. I referred you to this thread. But now I see in the code that the username regex uses an "i" flag which makes it case-insensitive:


    Removing the i would allow the regex to be case-sensitive, but that requires a file edit or addon.

    			$matchRegex = $this->getOption(self::OPTION_USERNAME_REGEX);
    			if ($matchRegex)
    				$matchRegex = str_replace('#', '\\#', $matchRegex); // escape delim only
    				if (!preg_match('#' . $matchRegex . '#i', $username))
    					$this->error(new XenForo_Phrase('please_enter_another_name_required_format'), 'username');
    					return false;
  16. ŽivaAkcija

    ŽivaAkcija Well-Known Member

    so cannot be resolved without plugin?
  17. Robert9

    Robert9 Active Member


    So this will still take "name" instead of "Name"?

    Is there a hook around this register test?
    Can i add some php code before?
    I would like to delete spaces and everything that is not allowed, set all to lower case and a ucfirst, bevor the regex starts. :)
  18. ŽivaAkcija

    ŽivaAkcija Well-Known Member

    yap i wonder why is not resolved in default option inside xenforo
    whynot likes this.
  19. Robert9

    Robert9 Active Member

    My changes in vb > register.php from 1912:

           // fix extra whitespace and invisible ascii stuff                                                                       
            $username = trim(preg_replace('#\s+#si', '', strip_blank_ascii($username, ' ')));                                       
            //// lower                                                                                                 
            $username = strtolower($username);                                                                                     
            // Umlauts
            $array_1 = array("ä","ö","ü","ß");                                                                                     
            $array_2 = array("ae","oe","ue","ss");                                                                                 
            for($x=0;$x<4;$x++) {                                                                                                                       
               $username = str_replace($array_1[$x],$array_2[$x],$username);                                                       
           // Only one!
           $username = str_replace("--","",$username);
           $username = str_replace("..","",$username);
           $username = str_replace("__","",$username);
           $username = str_replace("._","",$username);
           $username = str_replace(".-","",$username);
           $username = str_replace("-_","",$username);
           $username = str_replace("-.","",$username);
           $username = str_replace("_-","",$username);
           $username = str_replace("_.","",$username);       
           // Ucase first                                                                                                 
           $username = ucfirst($username);  
    For shure an addon would be nice, but it is not done in 2 minutes like changing the code,
    what can i do.

Share This Page