Tips and Tricks HQ Support Portal › Forums › WP eMember › WP eMember Tweaks › Spaces hyphens and commas in username
- This topic has 9 replies, 3 voices, and was last updated 12 years, 3 months ago by admin.
-
AuthorPosts
-
February 25, 2012 at 9:46 am #5646adam_paxtonMember
Hi,
Can you tell me how I would allow users to include spaces and other characters in their username please?
As far as I am aware WordPress does not block spaces or commas so I assume the restriction is being enforced by eMember?
Many thanks
February 26, 2012 at 1:51 am #42315adminKeymasterThe username field is restricted to letters, numbers and underscore so that this same username can be used as “Affiliate ID” if you are using the Affiliate plugin. The affiliate ID goes in the URL so there is a character limitation of what can be used in that field so we don’t run into an issue of malformed URL.
It is very common to restrict the username fields to only use letters and numbers. You will see that when creating a Gmail, Yahoo or Hotmail account they won’t let you use “space”, “comma”, “hypen” characters when choosing the username.
February 27, 2012 at 10:18 pm #42316adam_paxtonMemberExcellent,
Thank you for taking the time to respond to my post – really appreciate it.
However, the site I have developed is for a client and part of their requirement is that usernames can take a space. It was working previously so I can only assume it was a plugin update that has caused the issue of the enforced characters.
I understand what you are saying regarding it being both common and good practise but for my requirements I need to disable the validation. Is it possible and if so could you tell me how please?
Many thanks
February 28, 2012 at 5:15 am #42317adminKeymasterIt is not really recommended to change this validation rule as it can trigger other errors and we can’t support manually tweaked code errors. Anyway, if you want to play around this is what you need tweak:
Find the following code in the “emember_js_form_validation_rules.php” file
"onlyLetterNumberUnderscore": {
"regex": /^[0-9a-zA-Z_]+$/,
"alertText": "* "+'<?php echo EMEMBER_ALPHA_NUMERIC_UNDERSCORE;?>'
},Now you can change the value of the “regex” field to whatever characters you want to allow.
February 28, 2012 at 11:29 am #42318adam_paxtonMemberHi,
Thanks for highlighting the risks – I will try to avoid this in future.
When I complete the username and include spaces I don’t get the JavaScript invalid popup message appearing which is great. However, when I submit the form I get a message saying ‘Only Letter, Number, Underscore, Comma and Space allowed’ which is what I changed the message to be in the eng language file.
Is there a separate line of code that I need to edit which checks validity on form submission? Looks like the error validation code is being triggered as a server response which makes me think it’s PHP rather than JavaScript.
Hope you can help!
February 29, 2012 at 3:31 am #42319adminKeymasterYep, it is coming from the PHP file (this is to stop anyone from being able to inject stuff bypassing the JavaScript check). Find the following code block in the “emember_validator.php” file and modify as necessary:
function alphanumericunderscore($value){
if(preg_match("/^[0-9a-zA-Z_]{4,}$/", $value) === 0)
return true;
return false;
}February 29, 2012 at 11:27 pm #42320adam_paxtonMemberPerfect – you are a legend!
August 15, 2012 at 4:43 pm #42321primatedMemberHi, not actually being a programmer, more on the hack side how would I actually change those two bits of code to allow spaces in the user name?
On a site I am developing for a client, he is requiring that members use their real name as their user name, so using the space would be very helpful, I’m just not sure what PHP recognizes as a value for a space.
Can someone please be of assistance?
Thanks
August 16, 2012 at 12:09 am #42322primatedMemberHey, forget about that.
I did some Googling and got it figured out and it all seems to work.
Anyway you could make it so that people could have spaces unless they, clicked to enable the Affiliate plugin? This way it would keep everyone covered for support and still allow flexibility.
On my Clients site, they want people to use their real names, which requires a space. They are not doing and Affiliate program. eMember is a very cool, full functional program and I can do a lot with it and really like it.
If you can figure out a way to allow spaces for people not running Affiliate programs, that would really kick major arse!
August 16, 2012 at 10:58 pm #42323adminKeymasterGood to hear that you figured it out.
Using space in the “Username” is not a good practice in general. You will see that in most sites when you signup, they don’t allow you to use space in the username. There is a reason for that.
-
AuthorPosts
- You must be logged in to reply to this topic.