Validating Username

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #16
    Originally posted by pbmods
    Heya, Runway.

    What is the value of $username when the User inputs 'abc#123'?
    HEY YOUR BACK!!

    *goes to cafe/lounce to see announcement*

    I think he said the value is only "abc", the rest is truncated.

    he needs url_encoding i believe, as every body here posted (some more than once)

    PS: glad to see you back,

    Dan

    Comment

    • runway27
      Banned
      New Member
      • Sep 2007
      • 54

      #17
      validating # sign in php

      my question is about validation using php. i am validating a username which a user would

      enter and clicks on a image to find if that username is available. example if a user enters

      abc#123 php file is reading this value as abc ONLY which i do not want instead the php file

      should read as abc#123. following is the sequence of pages. please advice the solution.

      first page = register.php here a user enters a username and clicks on an image to find out

      if the username is available or not. using a javascript function of onclick i am reading the

      value entered in the form in javascript as
      =============== =============== ===============
      var useri = document.regist rationform.user name
      var valueofuseri = document.regist rationform.user name.value

      var recui = /^\s{1,}$/g;

      if ((useri.value== null) || (useri.value==" ") || (useri.length== "") ||

      (useri.value.se arch(recui))> -1)
      {
      alert("Please Enter a User Name")
      return false
      }

      window.open("ch eckusernamei.ph p?theusernameis ="+valueofuseri , "titleforavaila bilityi",

      "width=680, height=275, status=1, scrollbars=1, resizeable=yes" );

      =============== =============== ==============

      i have used a alert message in javascript to display the value, javascript is able to

      capture all the characters entered which is abc#123

      second page = checkusernamei. php = this file uses GET to read what was entered in the form.
      =============== =============== ==============
      $username = $_GET["theusernam eis"];

      if( $username == "" || !preg_match("/^[a-z0-9]+(?:_[a-z0-9]+)?$/i", $username) )
      {
      echo "username is blank or has special characters";
      }
      =============== =============== ==============
      the # sign is being ignored only if the image is clicked in order to check the username, if

      the user enters abc#123 and clicks the submit button without clicking on the checkuser image

      button then my php validation for username shows an error message.

      =============== =============== =============== =============== ==
      if( $username == "" || !preg_match("/^[a-z0-9]+(?:_[a-z0-9]+)?$/i", $username) )
      { echo "display error message for username"; }
      =============== =============== =============== =============== ==
      now the problem is with clicking the image only and passing the value to checkusernamei. php

      using GET method
      i have also used an echo statement in checkusernamei. php as
      echo "value of username is ". $username; = this displays abc and not abc#123

      how can i fix this problem wherein checkusernamei. php will be able to read abc#123. also in

      this checkusernamei. php file i have a select query which will read if the username already

      exists in the table. presently as checkusernamei. php is reading abc ONLY the select query is

      also passing abc and not abc#123

      $select = "Select username from table where username = '$username'";

      please advice.

      thanks.

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #18
        Dear runway27,

        When # goes in the URL, the text after the # is considered as anchor by the browser. When you are opening a new window with this code:[code=javascript]window.open("ch eckusernamei.ph p?theusernameis ="+valueofuseri , "titleforavaila bilityi", "width=680, height=275, status=1, scrollbars=1, resizeable=yes" );[/code]
        The URL is "checkusernamei .php?theusernam eis="+valueofus eri

        And when your user name is abc#123, your URL becomes:
        checkusernamei. php?theusername is=abc#123

        So what happens is, #123 is considered as an anchor bookmark(see point 2 here) in the page.

        With this, the value of your $_GET['theusernameis'] remains abc only.

        To escape this, you should use encodeURICompon ent in JavaScript.
        So just change the second like of your JavaScript as[code=javascript]var valueofuseri = encodeURICompon ent(document.regis trationform.use rname.value)[/code]
        If you want to encode it in PHP, after you click on the page and its opened in PHP, then that would be too late. As by that time your browser would have already considered text after # as anchor.

        I apologize that I answered you twice on the same question but could not make you understand why is it so.

        Hope you will get this this time.

        Regards

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #19
          Deja-vu.

          Hasn't this been asked like 3 times (and answered)?

          Comment

          • hsriat
            Recognized Expert Top Contributor
            • Jan 2008
            • 1653

            #20
            Originally posted by markusn00b
            Deja-vu.

            Hasn't this been asked like 3 times (and answered)?
            I too think so... ;)

            Comment

            • Atli
              Recognized Expert Expert
              • Nov 2006
              • 5062

              #21
              Originally posted by markusn00b
              Deja-vu.

              Hasn't this been asked like 3 times (and answered)?
              Indeed. This will be the second time I merge a duplicate thread with the original thread.

              runway27, you have been warned twice before about double-posting and using [code] tags, and you just keep ignoring us.

              This behavior is not acceptable and has just earned you a 1 week ban.
              I suggest you take that time to familiarize yourself with the Posting Guidelines.

              The next time you ignore the guidelines, the ban will be permanent.

              Moderator

              Comment

              • hsriat
                Recognized Expert Top Contributor
                • Jan 2008
                • 1653

                #22
                Originally posted by Atli
                This behavior is not acceptable and has just earned you a 1 week ban.
                aww.. this is gonna be harsh. But rules are rules.


                I didn't get one thing though... he never replied in the already started thread. He got many replies, but he didn't give a damn.

                What did he think about us?.....

                Comment

                • Markus
                  Recognized Expert Expert
                  • Jun 2007
                  • 6092

                  #23
                  Originally posted by ronverdonk
                  Sorry to disagree slightly here.
                  A destination anchor is not just, or only, a div. The destination anchors in HTML documents may be specified either by the A element (naming it with the name attribute), or by any other element (naming with the id attribute).

                  Ronald
                  I wasn't being specific to only divs.

                  Comment

                  • Markus
                    Recognized Expert Expert
                    • Jun 2007
                    • 6092

                    #24
                    Originally posted by hsriat
                    aww.. this is gonna be harsh. But rules are rules.


                    I didn't get one thing though... he never replied in the already started thread. He got many replies, but he didn't give a damn.

                    What did he think about us?.....
                    I just don't understand some people..

                    Could it've been a bot?

                    Comment

                    • hsriat
                      Recognized Expert Top Contributor
                      • Jan 2008
                      • 1653

                      #25
                      Originally posted by markusn00b
                      I just don't understand some people..

                      Could it've been a bot?
                      LOL!... and that bot has just got to ask a technical question in bytes?... not a good utility bot.

                      Comment

                      Working...