We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25551 ☆ A M B ☆
    • 1,231 Posts
    I have searched around the forum on how to stop new members from entering spaces or certain characters as their username. If there anyway to control what a user can input?
      Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
      AugmentBLU - MODX Partner

      BLUcart - MODX Revolution E-Commerce & Shopping Cart
      • 25551 ☆ A M B ☆
      • 1,231 Posts
      Anyone able to help with this one?
        Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
        AugmentBLU - MODX Partner

        BLUcart - MODX Revolution E-Commerce & Shopping Cart
        • 34017
        • 898 Posts
        i would do 2 things

        1. use a little ajax
        2. create a plugin for onbeforenewmember (or whatever it is), and do a check for a space in the name. If there is, stop the process and return to the page with an error message

        i say use ajax because it’ll be better for the user. but the plugin would be necessary if the user has js off.
          Chuck the Trukk
          ProWebscape.com :: Nashville-WebDesign.com
          - - - - - - - -
          What are TV's? Here's some info below.
          http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
          http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
          • 25551 ☆ A M B ☆
          • 1,231 Posts
          Is there nothing built in to modx or webloginpe to check for this as is? I use usernames to create aliases for documents and if there’s a space in the username then the space is replaced with a "_" in the alias which stops what I want to do from working.

          I’m not a programmer so I’m unsure what to do with the info you gave but thanks. I’ll do some more digging.
            Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
            AugmentBLU - MODX Partner

            BLUcart - MODX Revolution E-Commerce & Shopping Cart
            • 33992 ☆ A M B ☆
            • 455 Posts
            webloginpe.class.php line 548 (v 1.3.1)
            $lowercase = strtolower(str_replace(' ', '_', $username));

            you can replace this line with
            $lowercase = strtolower($username);

            or use anything you like instead "_" in main line and even add new filter by repeating replace line


            Quote from: rossco at Feb 20, 2009, 01:13 PM

            I have searched around the forum on how to stop new members from entering spaces or certain characters as their username. If there anyway to control what a user can input?
            I think, rejecting forbidden chars by javascript is simpler. something like this:
            ...<button name="register" onclick="javascript:if( !checkUsername() ) return false;">...
            
            function checkUsername()
            {
            	var username = document.getElementById("username_filed_Id").value;
            	
            	if(username.search(/@/) != -1)
            	{
            		alert("@ is not allowed");
            		return false;
            	}
            	return true;
            }

              God loves me. 【ツ】


              MODX.ir (Persian Support)

              Boplo.ir/modx/ (Persian)
              • 25551 ☆ A M B ☆
              • 1,231 Posts
              Hey AHHP,

              I changed the webloginpe class as you suggested and I tried the JS but neither worked.

              I put the following in my Register form

              <script type="text/javascript">
              function checkUsername()
              {
              	var username = document.getElementById("wlpeUserRegisterUserName").value;
              	
              	if(username.search(/@/) != -1)
              	{
              		alert("@ is not allowed");
              		return false;
              	}
              	return true;
              }
              </script>
                   <button type="submit" id="wlpeSaveRegisterButton" name="service" value="register" onclick="javascript:if( !checkUsername() ) return false;">Register</button>
              

              I tried using the username "my name@" and it still allowed it to register. I do however have another onclick event in the actual form to convert the username to lower case, would this effect it?
              <form id="wlpeUserRegisterForm" action="[~[*id*]~]" method="post" enctype="multipart/form-data" onsubmit="document.getElementById('username').value = document.getElementById('username'). value.toLowerCase();">


              Thanks for the help!
                Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
                AugmentBLU - MODX Partner

                BLUcart - MODX Revolution E-Commerce & Shopping Cart
                • 33992 ☆ A M B ☆
                • 455 Posts
                WebLoginPE converts username to lowercase itself here $lowercase = strtolower(str_replace(’ ’, ’_’, $username));

                it is better to use the function in username field with onkeyup event like this:
                <script type="text/javascript">
                function checkUsername()
                {
                	var username = document.getElementById("username").value;
                	var regex = /@/;
                	
                	if(username.search(regex) != -1)
                	{
                		alert(" \"@\" is not allowed");
                		document.getElementById("username").value = username.replace(regex, "");
                	}
                }
                </script>
                <input type="text" name="username" id="username" onkeyup="checkUsername();" />

                  God loves me. 【ツ】


                  MODX.ir (Persian Support)

                  Boplo.ir/modx/ (Persian)
                  • 25551 ☆ A M B ☆
                  • 1,231 Posts
                  The JS worked that time... how ever usernames are not converted to lowercase. I signed up using RRR and in the manager it was RRR. I know that webloginpe allows you to sign in using lower or uppercase but for the way I have setup one of my sites, you must sign in using lowercase letters. If you use and uppercase letter, some options are not available to the webuser. I allow webusers to upload images using Maxigallery and if the user signs in using anything other than all lower case letters, the manage button does not appear. I had posted that issue a while back but I resolved it myself with a simple JS to change the username to lowercase on sign in.

                  Anyway, could you tell me how I can extend the /@/ to cover other symbols such as "?" ";" etc? Also how do I include checking for spaces.

                  Thanks.
                    Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
                    AugmentBLU - MODX Partner

                    BLUcart - MODX Revolution E-Commerce & Shopping Cart
                    • 33992 ☆ A M B ☆
                    • 455 Posts
                    Quote from: rossco at Feb 26, 2009, 04:09 AM

                    Anyway, could you tell me how I can extend the /@/ to cover other symbols such as "?" ";" etc? Also how do I include checking for spaces.
                    Unfortunately I don’t know regular expression [Regex] undecided (i neeeeed it sad )
                    but you can find a lot of tutorials in web (search "javascript regular expression").

                    also here is some useful REGEXs and js lines for validating forms such as remove spaces or "http://" in url fields and ....
                    http://www.web-wise-wizard.com/javascript-tutorials/javascript-regular-expressions-regexp.html
                      God loves me. 【ツ】


                      MODX.ir (Persian Support)

                      Boplo.ir/modx/ (Persian)
                      • 25551 ☆ A M B ☆
                      • 1,231 Posts
                      Yeah I did search before I asked and tried a couple ideas but couldn’t figure it out lol.

                      I’ll check the link you posted and take it from there. Thanks for your time and help!
                        Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
                        AugmentBLU - MODX Partner

                        BLUcart - MODX Revolution E-Commerce & Shopping Cart