Jump to content

Recommended Posts

Yes, it should work however, it's not.

 

Generic tests (ALL numbers) works.

 

Then when I retested, checked on php.net it'sn ot meant to be fullproof.  It's not meant to work as a definitive.  if you have number's, and hten some letter's it let's it got through depending on the combination.

Anybody have something they use that is fullproof?

I would use if(!ereg("[0-9]+",$data)){ //send out an error

 

Or shorten the regex more into "\d+".

 

This will make sure that $data is any number of digits long. If you wanted to limit it you could use "[0-9]{min,max}". However, this won't allow for negatives vs. positives. But you could easily add that by putting a "-" in the very beginning of your character set, i.e. "[-0-9]+" should check all numbers as okay, whether or not they're negative.

// should be true
var_dump(is_numeric('0123.45e052'));
var_dump(is_numeric('0xFF'));

// should be false
var_dump(is_numeric('0123.45e'));
var_dump(is_numeric('01e23.456'));

 

output:

bool(true)

bool(true)

bool(false)

bool(false)

 

as expected, I think is_numeric is fullproof

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.