note 47490 deleted from function.is-numeric by nlopess
| From: | nlopess@php.net | Date: | Sun, 16 Jan 2005 12:42:18 +0000 |
| Subject: | note 47490 deleted from function.is-numeric by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-83438@lists.php.net to get a copy of this message | ||
Note Submitter:
----
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.