Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 422
0 Users 8 Guests Online

Limit username restrictions

Ok, so basically, this is a helpful snippit for people who only want their visitors to be able to register with the following characters, a-z, A-Z, 0-9,_, and -.

Find in register.php:
PHP Code
1
2
$adduser = mysql_query("INSERT INTO `members` (`username`, `password`, `email`, `userlevel`) VALUES('$username','$password','$email','2')");
echo "You are now registered,<br><br>You can now loggin to your account";


Before it, add this:
PHP Code
1
if (ereg("^[a-zA-Z0-9_]{3,16}$",$username)) {

after it add this:
PHP Code
1
2
3
}else{ 
echo "You're username contains invalid characters.";
}


and viola, you're done.

So, your final product should be something along these lines:

PHP Code
1
2
3
4
5
6
7
if (ereg("^[a-zA-Z0-9_]{3,16}$",$username)) {
    $valid = true;
$adduser = mysql_query("INSERT INTO `members` (`username`, `password`, `email`, `userlevel`,`ip`, `signupdate`) VALUES('$username','$password','$email','2','$ip','$datex')");
echo "<h2>Success!</h2> You are now registered, $username. You can now <a href='http://avidpictures.com/beta/login.php>login</a> to your account!</a>";
 }else{
     echo "Invalid username";
     }


Any questions or help, post and I'll do my best to help you. Remember, this also works for other input fields!
UrbanTwitch
Views:
7219
Rating:
Posted on Tuesday 18th November 2008 at 11:44 PM
Jakkkay
Jakkkay
Ill pay 20 bucks for a usersystem already made and can easily get installed by me :D if you ware interested email me at legitimateproductions@live.ca

Or add :D
Posted on Thursday 6th November 2008 at 01:16 AM
Dava
Dava
for those who want preg_match just use the following

Code
if (preg_match("/^[a-zA-Z0-9_]{3,16}$/",$username)) {
Posted on Wednesday 8th October 2008 at 01:27 PM
UrbanTwitch
UrbanTwitch
Show me your code.
Posted on Wednesday 8th October 2008 at 07:01 AM
jambomb
jambomb
Doesnt seem to work ?

I tryd my username like %$%£ $%£%^*((^ lol
Posted on Wednesday 8th October 2008 at 05:28 AM
Matt
Matt
ereg is slow, why dont you use preg_match?