Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form GET variable type

    Is there a way to make sure that the value entered into a text input is an integer (without using Javascript or some such nonsense)? I have a text input that should be only for integers, but even when you type a number in, PHP recognizes the passed variable as a string.

  • #2
    New Coder
    Join Date
    Oct 2006
    Posts
    82
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Try this

    Code:
    <?php
    
    $number = $_POST['inputBox'];
    
    if(is_numeric($number))
      {
        Code you want to run if number was inputted
      }
    else
      {
        Code you want to run if number was NOT inputted
      }
    
    ?>
    Is that what you're after?

  • #3
    New Coder
    Join Date
    May 2006
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So the is_numeric function will tell me if the value of a string variable is actually a number?

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    [quote=php.net]
    Finds whether the given variable is numeric. Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. Hexadecimal notation (0xFF) is allowed too but only without sign, decimal and exponential part.
    [/php]
    http://php.net/is-numeric

    might also want to take a look at http://php.net/filter

  • #5
    New Coder
    Join Date
    May 2006
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm... seems like I could make that work for me. Thanks guys.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •