Solved

verify input is int or double

Posted on 2003-12-08
1
449 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

630 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