PHP form textbox validation
Posted on 2004-03-23
I have a textbox on an order page. The user enters the quantity of the item that they want to buy, and then clicks an order button. What I want is a way to detect if it is an integer and at least 1.
$ValidInt = 0;
if ($quant > 0) // I was hoping any string would not pass this, though I think I am incorrect.
$ValidInt = 1;
That was my original attempt, but it does not seem to work. If the user enters a string or any combination of letters and numbers, then of course $ValidInt should remain 0. If it is a decimal, it should also remain zero. Finally, it must be at least 1. That is what I tried to accomplish, in a few different ways, the above seemed to be my best effort. Thanks!