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? Link to comment https://forums.phpfreaks.com/topic/46526-solved-check-an-input-string-for-data-types/ 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"; ?> Link to comment https://forums.phpfreaks.com/topic/46526-solved-check-an-input-string-for-data-types/#findComment-226468 Share on other sites More sharing options...
soycharliente Posted April 11, 2007 Author Share Posted April 11, 2007 You so smart! Gracias. Link to comment https://forums.phpfreaks.com/topic/46526-solved-check-an-input-string-for-data-types/#findComment-226477 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.