Jump to content

[SOLVED] Check an input string for data types


soycharliente

Recommended Posts

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?

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.