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)))
Re: Verify if input is of double value
is_double is not a function but the rest seems workable
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
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 :)