Jump to content

is_numeric


dreamwest

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

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.