Jump to content

[SOLVED] Need help with Check for invaild usernames!


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.');
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.