note 40393 deleted from function.is-int by nlopess
| From: | nlopess@php.net | Date: | Tue, 02 Mar 2004 17:38:52 +0000 |
| Subject: | note 40393 deleted from function.is-int by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-66122@lists.php.net to get a copy of this message | ||
Note Submitter: anyone
----
>> Test("Ten");
>> Test("Eleven");
>> What should the function return me???? TRUE or FALSE???
TRUE!!!!
The only reason we do not, is that it is not practical for US the programmers! If you ask a user her
age and she replies "thirteen" I would accept it, not reply "dumb user write a
number".
I am the dumb computer that doesn't understand, not her!
Had it been "practical" I would also accept "thirteen and not one more" or
"one less than my sister that registered an our ago" or any number in any language...
Do not forget WHY we do things!!!!
The only good reason to filter out entries is to avoid typos (and ambiguos situations).
If for instance asking user age, I would probably accept also 15.5 as a valid reply, but maybe a 155
year old man with trembling hand might have hit the "." as an error...
When to accept "strange" integers? The the real answer is "IT DEPENDS ON THE
SITUATION"!
You may use a simple and strict test, like testing for any char that is not in 0-9 range, in
situations where an error might be very critical (the reason they are not listed is just that they
are SIMPLE tests!) or use one of the said functions when errors are not critical and rejecting a
form is bad.
But, in any case, a "thirteen" answer cannot be a typo (well you know a monkey on a
keyboard might type the whole bible if you give her enough time...) so it should definitely be
accepted.
P.S. We leave the Test() function to accept any number in written English as an exercise to the
user... ;))