note 47491 deleted from function.is-numeric by crell
| From: | crell@php.net | Date: | Mon, 18 Apr 2022 14:58:33 +0000 |
| Subject: | note 47491 deleted from function.is-numeric by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218285@lists.php.net to get a copy of this message | ||
Note Submitter: mdallaire at virtuelcom dot com
----
Sometimes, we need to have no letters in the number and is_numeric does not quit the job.
You can try it this ways to make sure of the number format:
function new_is_unsigned_float($val) {
$val=str_replace(" ","",trim($val));
return eregi("^([0-9])+([\.|,]([0-9])*)?$",$val);
}
function new_is_unsigned_integer($val) {
$val=str_replace(" ","",trim($val));
return eregi("^([0-9])+$",$val);
}
function new_is_signed_float($val) {
$val=str_replace(" ","",trim($val));
return eregi("^-?([0-9])+([\.|,]([0-9])*)?$",$val);
}
function new_is_signed_integer($val) {
$val=str_replace(" ","",trim($val));
return eregi("^-?([0-9])+$",$val);
}
It returns 1 if okay and returns nothing "" if it's bad number formating.