PDA

Click to See Complete Forum and Search --> : Verify if input is of double value


Lex@SG
Oct 12th, 2005, 12:13 PM
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.

if (($pricePerUnit != "") && ((is_numeric($pricePerUnit) == false) || (is_double($pricePerUnit) == false)))

ninjanutz
Oct 12th, 2005, 08:45 PM
is_double is not a function but the rest seems workable

ninjanutz
Oct 12th, 2005, 08:50 PM
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

ninjanutz
Oct 12th, 2005, 09:02 PM
this however only worx for added values lke if someone typed it, if u want the form to do it automatically try this

$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 :)