Username Regular Expression Verification

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DHewes
    Member
    • Sep 2005
    • 81
    • 3.0.8

    [Forum] Username Regular Expression Verification

    On a new install I want to force users to choose usernames that can later be ported to a seperate application to create system email accounts for each user. Therefore I need to restrict the characters users can select when chosing their username. In the ACP, would this be the correct PCRE expression to enter to allow ONLY:

    A-Z
    a-z
    0-9
    special characters: - _ . +
    No spaces, and no other characters beyond the 4 above.

    Thanks!


    Code:
    ^[A-Z0-9.+-_]+$
  • Dody
    Senior Member
    • Aug 2004
    • 1896
    • 3.8.x

    #2
    Should be like the following:

    Code:
    ^[a-zA-Z0-9.+-_]+
    while(true){
    if(
    $someone->needsHelp() && $i->canHelp()) $post->help();
    if(
    $i->findBug()) $post->bug();
    }

    Comment

    • DHewes
      Member
      • Sep 2005
      • 81
      • 3.0.8

      #3
      Unfortunately both my original, as well as Dody's still allow special characters like / and ) and everything else I have tried. They do block spaces...so that is good I suppose... :-)

      Comment

      • Dody
        Senior Member
        • Aug 2004
        • 1896
        • 3.8.x

        #4
        Looks like I forgot the dollar sign

        Try this
        Code:
        ^[a-zA-Z0-9.+-_]+$
        while(true){
        if(
        $someone->needsHelp() && $i->canHelp()) $post->help();
        if(
        $i->findBug()) $post->bug();
        }

        Comment

        • DHewes
          Member
          • Sep 2005
          • 81
          • 3.0.8

          #5
          With the full admission that I have never read anything on regular expressions, I have found through some research and live trial and error that this code will force exactly what I need - the username to adhere to RFC 2822 (minus a couple never used special characters like % and $) so that I can directly create valid email addresses with the username + @mydomain.com.

          Code:
          ^[a-zA-Z0-9_\-\.\+]+$
          I also note that if I remove the a-z vB 4 still allows lower case. In reading, this does not appear to be entirely legit, but maybe it is there intentionally. The examples given when you click the help icon do not include the a-z either - so I believe this behavior to be intentional.

          Comment

          • DHewes
            Member
            • Sep 2005
            • 81
            • 3.0.8

            #6
            Dody - Unfortunately your code does not work. It still allows special characters like [ ] = etc., but it does block some special characters. I do not know nearly enough about RegEx to explain why. In regards to my code, I have also not through all the ALT characters at it, so some things may still slip by. This is not really a security feature for me though - it is a bonus of a free email account auto-created for my users, so if they go through that much trouble...screw 'em.

            Comment

            • Dody
              Senior Member
              • Aug 2004
              • 1896
              • 3.8.x

              #7
              I just tested, it works fine for me.
              while(true){
              if(
              $someone->needsHelp() && $i->canHelp()) $post->help();
              if(
              $i->findBug()) $post->bug();
              }

              Comment

              • DHewes
                Member
                • Sep 2005
                • 81
                • 3.0.8

                #8
                Is it possible that settings on the server itself dictate this? I cut and pasted your code and it allowed DHewes[+] as a name. In any case, I appreciate the assistance. I would be happy to set it back to your code if you want to see how it works on my server (a shared server environment).

                Comment

                • Andy
                  Senior Member
                  • Jan 2002
                  • 5886
                  • 4.1.x

                  #9
                  Admin CP -> Settings -> Options -> Username Regular Expression -> ^[a-zA-Z0-9]+$

                  This only allows alpha characters and numbers.

                  Comment

                  • Darkimmortal
                    Senior Member
                    • Apr 2009
                    • 686
                    • 3.8.11

                    #10
                    Could be the presence of a dot inside the square brackets, although I'm not sure if it takes on the same meaning.

                    Comment

                    • DHewes
                      Member
                      • Sep 2005
                      • 81
                      • 3.0.8

                      #11
                      Andy, thanks but that doesnt allow all that I need. The code I mentioned above IS WORKING PERFECTLY so as far as I am concerned I have what I need. I just find it curious that the same code works differently on my server as it does on Dody's server.

                      Comment

                      • Dody
                        Senior Member
                        • Aug 2004
                        • 1896
                        • 3.8.x

                        #12
                        As a workaround you can try disallowing these symbols:

                        ^[^#ยค%xxx]+$
                        while(true){
                        if(
                        $someone->needsHelp() && $i->canHelp()) $post->help();
                        if(
                        $i->findBug()) $post->bug();
                        }

                        Comment

                        • kushal
                          Member
                          • May 2006
                          • 33
                          • 4.2.X

                          #13
                          Though it's an old thread, but the topic is related. I wanted to disallow 'numeric only' username selection. How can I do that/
                          Professional Community Setup Solutions
                          vBaid.com: vBulletin Users
                          Invisionaid.com: IPB Users

                          Comment

                          widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                          Working...