Jump to content

[SOLVED] Need help with Check for invaild usernames!


Simon180

Recommended Posts

I been working on a small signup script for my site and I got it to work good not bad for first time but now I need to add a check on the username so if there entre invaild names like $e* or $h*t it will now allow them to make them I dont basic code but when I try to make any names it allways comes up the same username is bad even no normal names like Simon... can anyone help me please

 

here the code

 

$UsernameChars = "^[A-Za-z0-9]@-_SexShit"; // List of all banned words and letters
$UsernameGood = true;

if (!ereg($UsernameChars, $usernamefield))
{
$UsernameGood = false;
}
// checks for invalid characters in username
if ($UsernameGood == false && $UsernameCheck == true) {
die('The username is invalid because of reserved, or disallowed words.');
}

 

 

sorry about the bad words in script but thats what am trying to remove from being registred hope you dont mind

 

thanks

Slewis

<?php
$username = 'Daniel';

$bad_words = array('sex','shit');

$valid_username = ctype_alnum($username);
foreach($bad_words as $bad_word)
{
if(stripos($username, $bad_word))
{
	$valid_username = false;
	break;
}
}

echo "'{$username}' is ".(!$valid_username ? 'not' : null).' valid';
?>

updated to fit ;)

$badwords = array('thorpe', 'Daniel0', 'pie');

$badword = implode("|", $badwords);
$UsernameGood = true;
if (eregi($badword, $usernamefield))
{
$UsernameGood = false;
}
// checks for invalid characters in username
if ($UsernameGood == false && $UsernameCheck == true) {
die('The username is invalid because of reserved, or disallowed words.');
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.