whiteboikyle Posted June 6, 2008 Share Posted June 6, 2008 i think the function was something along the lines of eregi() or something.. but i need help restricting /\:*?"'<>|.,!@#$%^()[]{};`~=+ Pretty much make it only Numbers and Letters Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 6, 2008 Share Posted June 6, 2008 ctype_alnum(). Quote Link to comment Share on other sites More sharing options...
discomatt Posted June 6, 2008 Share Posted June 6, 2008 The easy way with regex is # Allows letters, numbers, underscores if ( preg_match( '[^\w]', $subject ) ) exit( 'Bad characters found' ); or # Allows letters, numbers if ( preg_match( '[^A-z0-9]', $subject ) ) exit( 'Bad characters found' ); Quote Link to comment Share on other sites More sharing options...
whiteboikyle Posted June 7, 2008 Author Share Posted June 7, 2008 okay well i do //Defines All The Users Inputs $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $mypassword2=$_POST['mypassword2']; $email=$_POST['email']; $passwordcount=$_POST['mypassword']; # Allows letters, numbers if(!preg_match('[^A-z0-9]', $myusername)) { session_register(bad_char); $_SESSION['bad_char'] = "<center><font color='red' size='1'>Invalid Charcter; Only Letters Or Numbers Can Be Used!</font></center>"; header("location:register.php"); } but it for some reason checks $mypassword to.. If i put !@#%!@#$ or anything in $mypassword it results to session_register(bad_char) but i only want it for $myusername Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 7, 2008 Share Posted June 7, 2008 Because you did the regex wrong. The guy who posted it did it right. Why can't people copy and paste anymore? if(preg_match('[^A-z0-9]', $myusername)) The ^ in the [ ] means 'not'. Quote Link to comment Share on other sites More sharing options...
whiteboikyle Posted June 7, 2008 Author Share Posted June 7, 2008 ooh i didn't know the ^ meant not sorry xD but now it wont show at all using if(preg_match('[^A-z0-9]', $myusername)) { session_register(bad_char); $_SESSION['bad_char'] = "<center><font color='red' size='1'>Invalid Charcter; Only Letters Or Numbers Can Be Used!</font></center>"; header("location:register.php"); } xD never used preg_match before.. sorry i am so complicated Quote Link to comment Share on other sites More sharing options...
whiteboikyle Posted June 7, 2008 Author Share Posted June 7, 2008 bump please help Quote Link to comment Share on other sites More sharing options...
whiteboikyle Posted June 8, 2008 Author Share Posted June 8, 2008 Does it have to be an Array? This is my code //Defines All The Users Inputs $myusername=$_POST['myusername']; $myusername2=$_POST['myusername']; $mypassword=$_POST['mypassword']; $mypassword2=$_POST['mypassword2']; $email=$_POST['email']; $passwordcount=$_POST['mypassword']; # Allows letters, numbers if(preg_match('/^[a-zA-Z0-9]+$/i', $myusername2)) { die("True"); session_register(bad_char); $_SESSION['bad_char'] = "<center><font color='red' size='1'>Invalid Charcter; Only Letters Or Numbers Can Be Used!</font></center>"; header("location:register.php"); } else { die("False"); } Quote Link to comment Share on other sites More sharing options...
effigy Posted June 9, 2008 Share Posted June 9, 2008 if (!preg_match('/^[a-z\d]+$/i', $myusername2)) { echo 'Invalid'; } Also see extract for your variable assignments. Quote Link to comment 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.