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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.