note 29396 deleted from function.is-numeric by crell

From: Date: Mon, 18 Apr 2022 14:58:54 +0000
Subject: note 29396 deleted from function.is-numeric by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218288@lists.php.net to get a copy of this message
Note Submitter: andi_nrw at hotmail dot com ---- <?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"; } ?>

« previous php.notes (#218288) next »