View Full Version : Disallow Special Chars in Username
THis would be great to have ( to lazy to make it ) but I have some poeple come on my site and register names like
~~~Mary~~~
and that for some odd reason makes me mad... so it would like a hack that only allows letters and numbers at registration.
thanks for your time
- Dan :ninja:
Logician
05-17-2002, 07:54 AM
In register.php find:
if (strlen($username)<$minuserlength) {
before that add:
------ cut -----------
// enter not allowed chars here seperated with a space:
$illegaluserchars=', . ~ ;';
$dontlethimuse=explode(" ",$illegaluserchars);
while (list($key,$val)=each($dontlethimuse))
{
if (strpos($username,$val))
{
eval("standarderror(\"".gettemplate("error_notallowedusername")."\");");exit;
}
}
------ cut -----------
Create a template named "error_notallowedusername" and specify your error message that will be posted if someone enters an invalid char.
This is not tested so it may require some polishing and debugging, but needless to say, you can handle it perfectly. Also dont forget to add another if clause if you want to ban space or ' char..Enjoy..
Regards,
Logician
Logician
05-17-2002, 08:05 AM
ops I've just noticed that you ONLY want numbers or letters in the username. So this is easier to apply:
if (!preg_match("/^[a-zA-Z0-9]+$/",$username))
{
eval("standarderror(\"".gettemplate("error_notallowedusername")."\");");exit;
}
thank you this really take some of my stress of coding off :)
Joshua Clinard
05-19-2002, 02:20 AM
I use the code in this (https://vborg.vbsupport.ru/showthread.php?postid=205862#post205862) post on my board.
The update in this (https://vborg.vbsupport.ru/showthread.php?postid=205986#post205986) post did not work at all for me, but I posted a fix for the problem I was having.
You can change the text to say anything you want.
Eggie
08-30-2005, 01:23 PM
sorry to bring back a REALLY OLD thread. but after endless searching, this was the only post regarding this I could find.
Will this code also work with vB 3.0.8 If not, could you please provide me with a code that would.
Logician
08-30-2005, 01:30 PM
sorry to bring back a REALLY OLD thread. but after endless searching, this was the only post regarding this I could find.
Will this code also work with vB 3.0.8 If not, could you please provide me with a code that would.
For vb 3.0.x, edit register.php, find:
// strip 'blank' ascii chars if admin wants to do so
BEFORE that line add (as a new line, NOT on the LEFT of it!):
// Logician Hack Start
// enter not allowed chars here seperated with a space:
$illegaluserchars=', . ~ ;';
$dontlethimuse = explode(" ",$illegaluserchars);
while (list($key,$val)=each($dontlethimuse))
{
if (strpos($_POST['username'],$val))
{
$errors[11] = "You can not use ..... characters in username!";
}
}
// Logician Hack End
Eggie
08-31-2005, 09:37 AM
great! and this will provent usernames from having a space also?
paul41598
08-31-2005, 05:55 PM
great! and this will provent usernames from having a space also?
thanks!
Andreas
08-31-2005, 06:02 PM
Maybe easier:
if (preg_match('/[,|\.|~|;]/', $_POST['username'])
{
$errors[11] = "You can not use ..... characters in username!";
}
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.