themistral Posted May 24, 2011 Share Posted May 24, 2011 Hi guys, I'm really struggling with what I think should be quite a simple regex. I need to check if a string contains only uppercase, numbers and symbols. I have tried 2 ways - neither of which seem to work. echo preg_match("/^([A-Z0-9.,'])$/", $string); echo !preg_match("/^([a-z])$/", $string); This is occurring within a loop - some entries contain lowercase characters but all results are returning false for the first expression and true for the second. Any help would be gratefully appreciated! Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted May 24, 2011 Share Posted May 24, 2011 echo preg_match("/^([A-Z0-9.,']+)$/", $string); Quote Link to comment Share on other sites More sharing options...
themistral Posted May 24, 2011 Author Share Posted May 24, 2011 Thanks JAY6390! At first that wasn't working...then I added a space and that now seems to work! echo preg_match("/^([A-Z0-9.,' ]+)$/", $string); Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted May 24, 2011 Share Posted May 24, 2011 you'll only need the space in there if you want to allow spaces as well Also, you don't need the ( ) around it unless you want to capture the string (which is kinda pointless since you are supplying the string in the first place) Quote Link to comment 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.