soycharliente Posted April 11, 2007 Share Posted April 11, 2007 I've searched through the archives, well just the first 5 pages, and didn't see anything that was similar to my question, but I hope that I'm not repeating anything. What's the best way to check to see if an input string is made of completely letters or completely numbers? I wrote this, but it doesn't seem to work. I'll follow it with an example. function checkForNumbers($s) { for($i = 0; $i < strlen($s); $i++) { if(!is_int($s[$i])) { return FALSE; } } return TRUE; } I used it like this... $foo = checkForNumbers("35436513"); if($foo) { echo "1"; } else { echo "0"; } And got back 0. Help? Quote Link to comment Share on other sites More sharing options...
trq Posted April 11, 2007 Share Posted April 11, 2007 Use preg_match. An example. <?php $string = "12345"; if (preg_match('/[0-9]/',$string)) echo "true"; else echo "false"; ?> Quote Link to comment Share on other sites More sharing options...
soycharliente Posted April 11, 2007 Author Share Posted April 11, 2007 You so smart! Gracias. Quote Link to comment 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.