Hi to everyone . I want to make my register.php for my web-site . I have some few questions about how to limit an alphanumeric username . Here is my register.php , please give me more suggestions about this: <?php include('connect.php'); ?> <form action="" method="post"> username <br><input name="username" type="text"><br> passowrd <br><input name="password" type="password"><br> repeat password <br><input name="rpassword" type="password"><br> email <br><input name="email" type="text"><br> <input name="submit" type="submit" value="submit"> </form> <?php if (isset($_POST['submit'])) { $error = array(); if ($_POST['username']) { $username = $_POST['username']; } else { $error[] = 'Ai uitat numele de utilizator'; } if ($_POST['password']) { if (strlen($_POST['password'])>=5 && strlen($_POST['password'])<=30) { if ($_POST['password'] == $_POST['rpassword']) { $password = md5($_POST['password']); } else { $error[] = 'Parolele nu coincid'; } } else { $error[] = 'Parola minim 5 maxim 30 caractere'; } } else { $error[] = 'Ai uitat parola'; } if ($_POST['email']) { $email = $_POST['email']; } else { $error[] = 'Ai uitat adresa de email'; } if (empty($error)) { // verifica daca userul scris mai exista $checkuser = mysql_query("SELECT username FROM members WHERE username='$username'"); $username_exist = mysql_num_rows($checkuser); if($username_exist > 0){ echo "I'm sorry but the username you specified has already been taken.Please pick another one."; unset($username); exit(); } else { //trimitere query catre baza de date $query = "INSERT INTO members (email, username, password, groupid) VALUES('$email', '$username', '$password' , 10)"; mysql_query($query) or die(mysql_error()); mysql_close(); echo " inregistrare reusita "; } } else { foreach ($error as $msg) { echo $msg . '<br />'; } } } unset($password); unset($rpassword); unset($email); ?> Code (markup): So when a user want to register at my site with a nickname like: /1^# to receiver an error like: We're sorry but you can use only alphanumeric username ! Thanks you. edit: a captcha system can help me very much!
you will need to use regex to validate all the input data (username,password,email). this can help you. and captcha is very simple to install google it.
if (!preg_match('/^[a-z0-9]+$/i', $username)) $error[] = "We're sorry but you can use only alphanumeric username!"; Code (markup):