Solved

verify input is int or double

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

828 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