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. 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 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)) {} 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 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
Archived
This topic is now archived and is closed to further replies.