Jump to content

Need to check if a string ($_POST) contains both numbers and letters


Beauford

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.