webref.eu Posted August 23, 2008 Share Posted August 23, 2008 I'd like to check a field for the following characters: < > @ and tell the user they aren't allowed to use them. What's the easiest way to do this? Thanks All. Quote Link to comment https://forums.phpfreaks.com/topic/121010-solved-disallow-certain-characters-from-a-field/ Share on other sites More sharing options...
Fadion Posted August 23, 2008 Share Posted August 23, 2008 The easiest way i can think of right now, should be: <?php $str = 'phpfreaks@'; if(strpos($str, '@')){ //you can do this for all the other characters using OR strpos($str, '<') and so on echo '@ found'; } ?> but im sure there are fancier ways. Quote Link to comment https://forums.phpfreaks.com/topic/121010-solved-disallow-certain-characters-from-a-field/#findComment-623812 Share on other sites More sharing options...
waynew Posted August 23, 2008 Share Posted August 23, 2008 Or: stristr(); Quote Link to comment https://forums.phpfreaks.com/topic/121010-solved-disallow-certain-characters-from-a-field/#findComment-623824 Share on other sites More sharing options...
Fadion Posted August 23, 2008 Share Posted August 23, 2008 stristr() is the case-insensitive strstr(), where in the manual it is stated: Note: If you only want to determine if a particular needle occurs within haystack , use the faster and less memory intensive function strpos() instead. Not that it will make a lot of difference, but just to let you know. Quote Link to comment https://forums.phpfreaks.com/topic/121010-solved-disallow-certain-characters-from-a-field/#findComment-623826 Share on other sites More sharing options...
waynew Posted August 23, 2008 Share Posted August 23, 2008 It would matter if the function is being used constantly. Good call. Quote Link to comment https://forums.phpfreaks.com/topic/121010-solved-disallow-certain-characters-from-a-field/#findComment-623828 Share on other sites More sharing options...
webref.eu Posted August 23, 2008 Author Share Posted August 23, 2008 Thanks guys, I have used the suggested solution. Rgds Quote Link to comment https://forums.phpfreaks.com/topic/121010-solved-disallow-certain-characters-from-a-field/#findComment-623931 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.