Simon180 Posted September 11, 2007 Share Posted September 11, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/68832-solved-need-help-with-check-for-invaild-usernames/ Share on other sites More sharing options...
MadTechie Posted September 11, 2007 Share Posted September 11, 2007 try $badwords = "pie|toe|cake|thorpe"; if (eregi($badwords, $username)) { exit("bad word"); } Quote Link to comment https://forums.phpfreaks.com/topic/68832-solved-need-help-with-check-for-invaild-usernames/#findComment-345984 Share on other sites More sharing options...
Daniel0 Posted September 11, 2007 Share Posted September 11, 2007 <?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'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/68832-solved-need-help-with-check-for-invaild-usernames/#findComment-345985 Share on other sites More sharing options...
MadTechie Posted September 11, 2007 Share Posted September 11, 2007 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.'); } Quote Link to comment https://forums.phpfreaks.com/topic/68832-solved-need-help-with-check-for-invaild-usernames/#findComment-345994 Share on other sites More sharing options...
Simon180 Posted September 11, 2007 Author Share Posted September 11, 2007 thank you very much that worked fine Quote Link to comment https://forums.phpfreaks.com/topic/68832-solved-need-help-with-check-for-invaild-usernames/#findComment-346020 Share on other sites More sharing options...
MadTechie Posted September 11, 2007 Share Posted September 11, 2007 Can you click solved bottom left (ps welcome to the board) Quote Link to comment https://forums.phpfreaks.com/topic/68832-solved-need-help-with-check-for-invaild-usernames/#findComment-346021 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.