Results 1 to 4 of 4

Thread: Verify if input is of double value

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2004
    Posts
    49

    Question Verify if input is of double value

    Hi,

    I would like to know how do i validate a field that complies with the following conditions:

    1) Must Not Be Empty
    2) Must Be Numeric
    3) Must Be Double (Eg. 1.00) [Up Only Two Decimal Places Allowed]

    I have personnally came up with this but it can't work.

    PHP Code:
    if (($pricePerUnit != "") && ((is_numeric($pricePerUnit) == false) || (is_double($pricePerUnit) == false))) 
    ______________________________________

    Warmest Regards,

    Lex
    ______________________________________



    :|: Don't Mess With The Predator :|:

  2. #2
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: Verify if input is of double value

    is_double is not a function but the rest seems workable

  3. #3
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: Verify if input is of double value

    try this instead "^([0-9])(.{1}[0-9]{2})?$" wat this does ... or should do ive never used this is let u have any number from 0-9 and as many numbers as they want then it adds a decimal and allows only 2 numbers after the decimal

  4. #4
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: Verify if input is of double value

    this however only worx for added values lke if someone typed it, if u want the form to do it automatically try this
    Code:
    $variable_containing_number = number_format ($same_variable, 2);
    this adds commas to thousands and adds a decimal point and also makes sure 2 digits are added after so if u have 4365 it will be 4,365.00 and if u have 43.567567 it will be 43.57 hope this helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width