Solved

verify input is int or double

Posted on 2003-12-08
1
442 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
Populate custom post type/custom fields from an external database in WordPress 3 80
Log in through ID 5 36
Wordpress Query 5 42
Dump data from mysql to xls php 10 16
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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 dynamically set the form action using jQuery.

713 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