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 Link to comment https://forums.phpfreaks.com/topic/109046-restrict-charcters/ Share on other sites More sharing options...
DarkWater Posted June 6, 2008 Share Posted June 6, 2008 ctype_alnum(). Link to comment https://forums.phpfreaks.com/topic/109046-restrict-charcters/#findComment-559429 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' ); Link to comment https://forums.phpfreaks.com/topic/109046-restrict-charcters/#findComment-559450 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 Link to comment https://forums.phpfreaks.com/topic/109046-restrict-charcters/#findComment-559594 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'. Link to comment https://forums.phpfreaks.com/topic/109046-restrict-charcters/#findComment-559599 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 Link to comment https://forums.phpfreaks.com/topic/109046-restrict-charcters/#findComment-559606 Share on other sites More sharing options...
whiteboikyle Posted June 7, 2008 Author Share Posted June 7, 2008 bump please help Link to comment https://forums.phpfreaks.com/topic/109046-restrict-charcters/#findComment-559994 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"); } Link to comment https://forums.phpfreaks.com/topic/109046-restrict-charcters/#findComment-560223 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. Link to comment https://forums.phpfreaks.com/topic/109046-restrict-charcters/#findComment-561119 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.