Hentet fra
http://www.php.net/is_numeric :
<?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"; //// is_numeric TRUE
} else {
print "Answer 2"; //// is_numeric FALSE
}
?>
Den sikrer dig at input kun kan indeholde tegnene 0-9 og ikke 1e5 fx :)
//Geert