note 47490 added to function.is-numeric

From: Date: Thu, 18 Nov 2004 00:23:25 +0000
Subject: note 47490 added to function.is-numeric
Groups: php.notes 
Request: Send a blank email to php-notes+get-80678@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/function.is-numeric.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47490 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47490&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47490&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47490&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47490&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47490&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47490&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47490&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#80678) next »