ukscotth Posted July 21, 2011 Share Posted July 21, 2011 Hi all, Is there an easy way to check to see if a string only contains letters and numbers ? Thanks in advance, Scott. Quote Link to comment https://forums.phpfreaks.com/topic/242539-check-that-string-only-contains-letters-and-numbers/ Share on other sites More sharing options...
Porl123 Posted July 21, 2011 Share Posted July 21, 2011 $foo = 'adGH323h'; if(!ctype_alnum($foo)) // bad else // ok Quote Link to comment https://forums.phpfreaks.com/topic/242539-check-that-string-only-contains-letters-and-numbers/#findComment-1245595 Share on other sites More sharing options...
trq Posted July 21, 2011 Share Posted July 21, 2011 if (preg_match('/[a-zA-Z0-9]+/', $str)) {} Quote Link to comment https://forums.phpfreaks.com/topic/242539-check-that-string-only-contains-letters-and-numbers/#findComment-1245599 Share on other sites More sharing options...
ukscotth Posted July 21, 2011 Author Share Posted July 21, 2011 Perfect. Thankyou Quote Link to comment https://forums.phpfreaks.com/topic/242539-check-that-string-only-contains-letters-and-numbers/#findComment-1245600 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.