acctman Posted February 7, 2008 Share Posted February 7, 2008 I would like to have the code re-written so that it rejects all characters that is not A-Z,a-z,0-9 //illegal characters in username? $illegal = array('#','?','&','"','/','%','!','$','\'','*','-','_','~'); foreach ($illegal as $value) if (strpos($en['user'],$value) !== false) $ill = true; if ($ill) $err .= _reg_illegal.'<br>'; Quote Link to comment https://forums.phpfreaks.com/topic/89870-rejecting-characters/ Share on other sites More sharing options...
Stooney Posted February 7, 2008 Share Posted February 7, 2008 php.net/preg_match Quote Link to comment https://forums.phpfreaks.com/topic/89870-rejecting-characters/#findComment-460585 Share on other sites More sharing options...
acctman Posted February 7, 2008 Author Share Posted February 7, 2008 if someone can help me with recoding this that would be great Quote Link to comment https://forums.phpfreaks.com/topic/89870-rejecting-characters/#findComment-460701 Share on other sites More sharing options...
aschk Posted February 7, 2008 Share Posted February 7, 2008 Deary me, too busy wanting to not actually look it up eh... $regex = '/([a-z0-9]+)/i'; if(preg_match($regex,$string)){ echo "it's good"; } else { echo "it's bad"; } What about spaces? Quote Link to comment https://forums.phpfreaks.com/topic/89870-rejecting-characters/#findComment-460708 Share on other sites More sharing options...
acctman Posted February 7, 2008 Author Share Posted February 7, 2008 Deary me, too busy wanting to not actually look it up eh... $regex = '/([a-z0-9]+)/i'; if(preg_match($regex,$string)){ echo "it's good"; } else { echo "it's bad"; } What about spaces? no spaces. thanks Quote Link to comment https://forums.phpfreaks.com/topic/89870-rejecting-characters/#findComment-460725 Share on other sites More sharing options...
acctman Posted February 7, 2008 Author Share Posted February 7, 2008 how would i apply this to my existing code? //illegal characters in username? $illegal = array('#','?','&','"','/','%','!','$','\'','*','-','_','~'); foreach ($illegal as $value) if (strpos($en['user'],$value) !== false) $ill = true; if ($ill) $err .= _reg_illegal.'<br>'; Quote Link to comment https://forums.phpfreaks.com/topic/89870-rejecting-characters/#findComment-460729 Share on other sites More sharing options...
aschk Posted February 7, 2008 Share Posted February 7, 2008 Read my code and figure it out Quote Link to comment https://forums.phpfreaks.com/topic/89870-rejecting-characters/#findComment-460734 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.