Beauford Posted November 19, 2008 Share Posted November 19, 2008 This is probably so simple a 10 year old could do it, but for the life of me, after hours of searching and trying all sorts of combinations of ctype, is_numeric, ereg, etc., I'm stumped. I need to check if a string ($_POST) contains both numbers and letters. If it does I need to post an error, if it contains just numbers I need to do something, and if it contains just characters do something else. No punctuation at all. If anyone can shed some light on this it would be appreciated. Thanks Link to comment https://forums.phpfreaks.com/topic/133289-need-to-check-if-a-string-_post-contains-both-numbers-and-letters/ Share on other sites More sharing options...
genericnumber1 Posted November 19, 2008 Share Posted November 19, 2008 is_numeric($var) will check to see if it's numbers preg_match('%^[A-Za-z]+$%', $var) will check to see if it's letters preg_match('%^[A-Za-z0-9]+$%', $var) will check to see if it's alphanumeric You should favor the most common input first in the if() statements, if there's no specific common inputs, you should use the order above as they're ordered from fastest to slowest. Link to comment https://forums.phpfreaks.com/topic/133289-need-to-check-if-a-string-_post-contains-both-numbers-and-letters/#findComment-693235 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.