Solved

verify input is int or double

Posted on 2003-12-08
1
439 Views
Last Modified: 2010-08-05
I need to verify that input given in a form field is an int or double...  The number they enter should be a price, so I'm guessing that the user will either enter: 5 or 5.00

How can I check this?
0
Comment
Question by:msknr
1 Comment
 
LVL 1

Accepted Solution

by:
Rayni earned 25 total points
ID: 9898520
// Checks To See If Numeric
if (is_numeric($price))
{
    // Checks if price is a integer
    if (is_int($price))
    {
         print "Is a integer";
    }
    // Checks if price is a double
    if (is_double($price))
    {
         print "Is a double";
    }
}

In this code you will want to use is_numeric first to even see if the price is numberic or a numberic string. This will help if your int / double checking code is very long and you dont want to have to run it unless the price is a number.

is_int while check to see if price is a int in this code, and is_double will check to see if price is a float since is_double is only alias of is_float. You can still use it for your purposes though.

Hope this helps you.

- Daniel
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question