spires Posted June 14, 2010 Share Posted June 14, 2010 Hi I want to check if a string has numbers in it. I've tried using is_numeric, but this on returns true if the string is all numeric. Not if it's a combination of characters and numbers. How can I check to see if my sting contains numbers. Example: Spires01 -- Should return True Spires -- Should return false Thanks Link to comment https://forums.phpfreaks.com/topic/204716-is_numeric/ Share on other sites More sharing options...
Adam Posted June 14, 2010 Share Posted June 14, 2010 Simplest way in my opinion would be to just use regex: if (preg_match('/[0-9]/', $str)) { // contains a number } Link to comment https://forums.phpfreaks.com/topic/204716-is_numeric/#findComment-1071767 Share on other sites More sharing options...
ZachMEdwards Posted June 15, 2010 Share Posted June 15, 2010 Using the \d token: if(preg_match('/\d/', $str)) { } Link to comment https://forums.phpfreaks.com/topic/204716-is_numeric/#findComment-1072230 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.