acctman Posted February 7, 2008 Share Posted February 7, 2008 I would like to have the code re-written so that it will rejects all characters that are not A-Z,a-z,0-9. please do not reply if you do not wish to help out. thanks. //illegal characters in username? $illegal = array('#','?','&','"','/','%','!','$','\'','*','-','_','~'); foreach ($illegal as $value) if (strpos($en['user'],$value) !== false) $ill = true; if ($ill) $err .= _reg_illegal.'<br>'; Link to comment https://forums.phpfreaks.com/topic/89944-solved-code-rewrite-help-needed/ Share on other sites More sharing options...
thebadbad Posted February 7, 2008 Share Posted February 7, 2008 Then you want to check if the username is alphanumeric. Use ctype_alnum(): <?php //illegal characters in username? if (!ctype_alnum($en['user'])) $err .= _reg_illegal.'<br>'; ?> Link to comment https://forums.phpfreaks.com/topic/89944-solved-code-rewrite-help-needed/#findComment-461118 Share on other sites More sharing options...
acctman Posted February 7, 2008 Author Share Posted February 7, 2008 Then you want to check if the username is alphanumeric. Use ctype_alnum(): <?php //illegal characters in username? if (!ctype_alnum($en['user'])) $err .= _reg_illegal.'<br>'; ?> wow that's it, using !ctype_alnum takes care of everything? that really shorten the coding by a lot. Link to comment https://forums.phpfreaks.com/topic/89944-solved-code-rewrite-help-needed/#findComment-461136 Share on other sites More sharing options...
thebadbad Posted February 7, 2008 Share Posted February 7, 2008 Yep, that's all you need. Link to comment https://forums.phpfreaks.com/topic/89944-solved-code-rewrite-help-needed/#findComment-461172 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.