View Full Version : Prevent use of symbols in usernames
Joshua Clinard
12-09-2001, 08:18 PM
I don't want people to be able to sign up with symbols in their usernames, like the forwards slash, and the paranthases, and so on. The only symbol I want people to be able to use in thier username is the underscore. No periods, commas, or other symbols or punctuation marks. Is there a way to prevent this?
Scott MacVicar
12-09-2001, 10:09 PM
open register.php
look for
if (strlen($username)<$minuserlength) {
eval("standarderror(\"".gettemplate("error_usernametooshort")."\");");
exit;
} elseif (strlen($username)>$maxuserlength) {
eval("standarderror(\"".gettemplate("error_usernametoolong")."\");");
exit;
}
below it add
if(!preg_match("/^[a-zA-Z_0-9]+$/", $username)) {
eval("standarderror(\"Invalid Characters you can only use a-z, 1-9 or an underscore in your username.\");");
exit;
}
Joshua Clinard
12-10-2001, 12:31 AM
Thanks. I'm just curious, but has this been tested?
Scott MacVicar
12-10-2001, 12:08 PM
Yeah it will work, it allow characters for a-z A-Z underscore and numbers in the range 0-9.
Hence the
a-zA-Z_0-9
but i believe that
if (!preg_match("/^\w+$/", $username)) {
eval("standarderror(\"Invalid Characters you can only use a-z, 1-9 or an underscore in your username.\");");
exit;
}
as \w represents word in perl thought it depends on locale settings
Joshua Clinard
12-16-2001, 07:48 PM
I didn't realize that this hack was also going to prevent the use of spaces. I don't want it to do that. Is there anyway to fix that? If I just typed in a space after the _ would that do it? By the way, I don't get what you were trying to say in your last post! Can you tell me what that means?
Joshua Clinard
12-18-2001, 03:50 PM
Can someone please help? I want to get this fixed.
StarBuG
01-08-2002, 03:07 PM
ever tried to use the html code for space in that definition?
"& n b s p ;" or "& # 1 6 0 ;" (without the spaces and "!)
like
if(!preg_match("/^[a-zA-Z_0-9& n b s p ;]+$/", $username)) {
eval("standarderror(\"Invalid Characters you can only use a-z, 1-9 or an underscore in your username.\");");
exit;
}
(also without spaces of course)
don?t know if it works but it is woth a try ;)
Greetings
StarBuG
Joshua Clinard
01-10-2002, 03:03 PM
The answer is to add a space after 9 in this code [a-zA-Z_0-9 ]
This has been tested. Thanks to Hoojx for help with this.
Scott MacVicar
01-10-2002, 03:25 PM
this works as well
if (!preg_match("/^w+$/", $username)) {
eval("standarderror(\"Invalid Characters you can only use a-z, 1-9 or an underscore in your username.\");");
exit;
}
How can I allow a dash (-) aswell? Coz when I added it it didn't seem to work!
--Sion
Logician
06-27-2002, 10:38 AM
use in this format:
[a-zA-Z_0-9\- ]
How can I prevent ppl signing up with - and _ at the beginning/end of their usernames, so that they're valid for email addresses (ie. username@mydomain.com)
Thanks!
Joshua Clinard
08-30-2002, 04:05 PM
Glad someone else got some use out of this mod. I thought I was the only one using it.
Maybe it should be released..
stan111
02-01-2007, 05:04 AM
how come i can't find any of those code under register.php
Princeton
02-01-2007, 01:31 PM
you brought up an old thread .... check the date :D
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.