Jump to content

Recommended Posts

Yes, you would have to remove spaces from your string, as I don't think your string will be recognised as a number if it has spaces in.  You'd have to write a routine to remove spaces and then you can check for a number as follows:

 

//Protection from hackers.  Check ProductId is just a number
$TestForNumber = is_numeric($ProductId);
If ($TestForNumber == 0) {
echo "Sorry, the Product Id tried is not allowed.";
exit();
}

 

Rgds

Link to comment
https://forums.phpfreaks.com/topic/160360-is_numeric/#findComment-846224
Share on other sites

A string needs quotes. And you can use preg_match(), allowing digits and whitespace:

 

<?php
$string = '13530 21333 16945 22819 24170 31196 19209';
if (preg_match('~^[0-9\s]+$~D', $string)) {
//string only contains digits and/or whitespace
}
?>

 

Thanks. I gotta learn preg match one day

Link to comment
https://forums.phpfreaks.com/topic/160360-is_numeric/#findComment-846228
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.