Hey,

Ok I am creating a shopping cart and I am having a problem with something. When a user goes to their basket, they can edit their quantity for items, I need a way of checking that what they enter in this textbox is a numeric/integer value.

For example, if they type in t4, I want it to strip the t and put 4 in the value...

If they type ta or anything that is not numeric, I want it to leave the value alone.

This is my current code for modifying products:

PHP Code:
// Modify quantity of cart if done in checkout
function modify_quantity($product$quantity) {
    
    
// Make sure quantity is an int
    
$quantity $this->check_int($quantity);
    
    
// Quantity is less than 0, delete item from cart
    
if($quantity <= 0) return $this->delete_item($product);
    
    
// Limit amount of products to be ordered at one time
    
if($quantity 30) return false;
    
    
// Check if quantity selected is greater than available
    
$chk $this->check_quan($product$quantity);
    
    
// Quantity selected is lower than available, ok
    
if($chk == 1) {
    
        
// No problems, update users cart
        
$query"UPDATE tbl_basket
                SET fld_amount='"
.$quantity."'
                WHERE fld_cartid='"
.$this->cart_id."' AND fld_pid='".$product."'";
        
        
mysql_query($query$this->dblink) or die ("Cannot select required information. "
            
// .mysql_error()
        
);

        return 
true;
    
    }
// end function 
Now I have tried all kinds of things for is_numeric to is_int etc, nothing seems to work...

This is the function I am currently trying out:

PHP Code:
function check_int($value) {
// use this function to make sure a value is of the correct format (int)
    
    // value is an integer, use it
    
if (is_numeric($value))
    { 
        
// Make sure value is numeric and change into an integer
        
$f_value settype($value'integer');
        
        return 
$f_value;
    
    
// value not an integer, do not use
    
} else {
    
        return 
false;
    
    }
    
// end function 
Problem is, if I type in a letter, it removes the item from the cart, and if I put in an integer to update the quantity, it does nothing...

Any ideas?

Cheers,
Chris