note 47457 rejected from function.is-numeric by sean

From: Date: Wed, 17 Nov 2004 23:33:33 +0000
Subject: note 47457 rejected from function.is-numeric by sean
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-80675@lists.php.net to get a copy of this message
Note Submitter: mdallaire at virtuelcom dot com ---- I very much like those fuctions. It removes spaces. For float numbers, it allows dot or coma for decimal separator but only one of them in the value. It allows the number to have a decimal separator with no number after it. But does not allow a leading separator. For signed numbers, the minus symbol must be in front. The value can only be composed of numbers. 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) { echo $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); } You can add features to change the decimal separator or modify above [\.|,] to \. to accept only a dot. Maybe the trim and replace can be done at the same time or the eregi, but since I never encounter any problem using them like this, I never tried to modify them again. Theyreturn 1 if okay and returns nothing "" if bad number formating. Hope they will be as useful for you as they are for me.

« previous php.notes (#80675) next »