Solved

verify input is int or double

Posted on 2003-12-08
1
433 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now