checking to see if value is a integer from a form text field
| From: | Joseph H Blythe | Date: | Sat, 17 Feb 2001 01:35:20 +0000 |
| Subject: | checking to see if value is a integer from a form text field | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-40015@lists.php.net to get a copy of this message | ||
hey,
I have a strange problem, when a user inputs the quantity into a text input field in a cart, I want
to be able to test to see if the value is a integer if it isn't then default it to 1
if ( !is_int($Qty) ) {
$Qty = 1;
}
Looks ok, should work in theory, but it doesn't if I use this test, the update on the database
fails, take it out and it works, so if a user was to type "f" in the quantity field in the
cart and hit update because the quantity field is int(2) in the database it will default to 0 which
I do not want. I have also tried to set the type before the update like so:
$Qty = settype($Qty, "integer");
This also will make the update fail, how would I make sure a user does not type characters in the
quantity field without using javascript or ereg stuff to check the values? I just want to default
the quantity to 1 if a invailid quantity is inputted.
If there is no obvious soulution then I will use a piece of javascript to check the field onSubmit
for illegal characters and alert the user I guess.
Regards,
Joseph