aeboi80 Posted January 11, 2011 Share Posted January 11, 2011 I have a keyword string which I need to verify only contains the following character set 0123456789abcdefghijklmnopqrstuvwxyz If it contains anything but 0123456789abcdefghijklmnopqrstuvwxyz then I need to mark it as invalid. if ($keyword contains ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+{}|":<>?/.,;'[]\=-){ $Error_msg = "invalid keyword"; } I don't really know much about preg_replace or similar functions...but I presume I would need to use something like that. I appreciate any guidance/examples. Quote Link to comment https://forums.phpfreaks.com/topic/224044-validate-characters-in-a-string/ Share on other sites More sharing options...
Pikachu2000 Posted January 11, 2011 Share Posted January 11, 2011 This ought to point you down the right path. $string = 'abcdefghi12345A'; if(preg_match('~[^a-z0-9]~', $string) ) { echo 'Bad chars'; } Quote Link to comment https://forums.phpfreaks.com/topic/224044-validate-characters-in-a-string/#findComment-1157744 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.