note 29396 added to function.is-numeric
| From: | andi_nrw at rack1 dot php dot net | Date: | Wed, 12 Feb 2003 14:25:15 +0000 |
| Subject: | note 29396 added to function.is-numeric | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-43822@lists.php.net to get a copy of this message | ||
<?php
/* This function is not useful if you want
to check that someone has filled in only
numbers into a form because for example
4e4 and 444 are both "numeric".
I used a regular expression for this problem
and it works pretty good. Maybe it is a good
idea to write a function and then to use it.
$input_number = "444"; // Answer 1
$input_number = "44 "; // Answer 2
$input_number = "4 4"; // Answer 2
$input_number = "4e4"; // Answer 2
$input_number = "e44"; // Answer 2
$input_number = "e4e"; // Answer 2
$input_number = "abc"; // Answer 2
*/
$input_number = "444";
if (preg_match ("/^([0-9]+)$/", $input_number)) {
print "Answer 1";
} else {
print "Answer 2";
}
?>
--
http://www.php.net/manual/en/function.is-numeric.php
http://master.php.net/manage/user-notes.php?action=edit+29396
http://master.php.net/manage/user-notes.php?action=delete+29396
http://master.php.net/manage/user-notes.php?action=reject+29396