Not Solved Prevent only numbers in username
#1
Not Solved
I don't think I've seen this anywhere before, but what code needs to be added or changed so that when members register, they can't only use numbers in their username? Meaning, they have to use at least one letter or they get an error? Thanks...
Jude

If I post in your thread, please do not PM me for more help! Thanks!


Reply
#2
Not Solved
Hmm..interesting request. Can I ask why you feel this is important? Some people do like to use a number for their names.

As for the code...you will basically need to add an if statement that if no letters exist error.

Here is the php function to see if all the characters are numeric.

http://us3.php.net/manual/en/function.ctype-digit.php

If this returns true you should error.

Goodluck.
Reply
#3
Not Solved
May I suggest a new hook so that plugins can easily denounce unacceptable usernames? The hook would return null or the empty string if it doesn't like the suggested name. A single negation would render that username unusable.
Reply
#4
Not Solved
"member_do_register_start" I believe is the hook for the registration page.

bah...I just went and made you a quick plugin.

<?php

/*
Plugin Number Username
(c) 2006 by democracyforums.com Labrocca
Website: http://www.mybbcentral.com
*/

function number_username_info()
{
	return array(
		"name"			=> "Number Usernames",
		"description"	=> "Prevents users registering with a number only username.",
		"website"		=> "http://www.democracyforums.com",
		"author"		=> "labrocca",
		"authorsite"	=> "http://www.mybbcentral.com",
		"version"		=> "1.0",
	);
}

$plugins->add_hook("member_do_register_start", "number_username");


function number_username_activate()
{
}

function number_username_deactivate()
{
}

function number_username()
{
	global $mybb, $session, $db;
	if(ctype_digit($mybb->input['username']))
		{
			error("Sorry, you cannot register an all number username.");
		}
}

?>


Attached Files
.php   number_username.php (Size: 802 bytes / Downloads: 74)
Reply
#5
Not Solved
Nice solution, labrocca. However, 2 things need to be kept in mind. Firstly, usernames need to be checked for both member_do_register_start and usercp_do_changename_start. Secondly, plugins should not perform non-undoable actions (such as updating database fields) in any of the _start hooks.

Since both member_do_register_start and usercp_do_changename_start have access to $mybb->input['username'], you can use the same function for both hooks.
Reply
#6
Not Solved
I just did as the OP asked...I really don't want to spend more time on a plugin I think is pointless.  
Reply
#7
Not Solved
labrocca Wrote:Can I ask why you feel this is important?  Some people do like to use a number for their names.  

Because we're people, not robots, and I refuse to call one of my members 12345!!!

And if you thought it pointless, why did you make it?  Big Grin  Though I appreciate it, did you put in enough effort so that it will work or are laie_techie's concerns a problem? Toungue
Jude

If I post in your thread, please do not PM me for more help! Thanks!


Reply
#8
Not Solved
The plugin works...I tested it. I didn't make it to work with username changes.  I made it because I could.  And a member could still name themselves "three five two" if they want.  Members should be able to choose what they wish to be called imho.  Of course it's your forum and you can run it how you want.

If you are concerned about the name change try adding after this line:

$plugins->add_hook("member_do_register_start", "number_username");

This...

$plugins->add_hook("usercp_do_changename_start", "number_username");

Not tested but it should work.
Reply
#9
Not Solved
No, I'm not concerned about the plugin changing names already assigned.  I'll just do that myself, but I wanted to stop any new members from getting just an all number name!  I would actually prefer they don't use any numbers, since I think that looks tacky, but I won't totally force my will on them...but I don't want all number usernames on my forum, which is why I started this thread!  Thanks for testing it though!  I'll be sure to add it to my site!  Big Grin

edit: I just found something interesting. There is error_invalidusername in the member language file that puts out an error that the username must be alphanumeric, but I can't find a place to activate this option. Was the error put it but the code not entered to trigger it???
Jude

If I post in your thread, please do not PM me for more help! Thanks!


Reply
#10
Not Solved
Alphanumeric means letters and numbers. In case a member tries to use characters like $#& for their name.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)