Possible Duplicate:
PHP regex - valid float number
what will be regular expression in php as well as for javascript for float numbers?
I waht to match values like 3, 3.3 or 0.3 and 0
Possible Duplicate:
PHP regex - valid float number
what will be regular expression in php as well as for javascript for float numbers?
I waht to match values like 3, 3.3 or 0.3 and 0
There is no token for float numbers. If you want to match a float you have to use digit + point + digit, something like this:
\d+(\.\d+)?
It depends on what you want :
Only check? do as Florian Margaine said : is_numeric($nb) in PHP for float numbers and ctype_digits($nb) for integers. in JS !isNaN(+nb); for float and typeof($nb) == "Integer" for integers.
If you want to convert your numbers (and check in the same time) :
//for floats
$floatNb = (float) $nb;
if($floatNb != 0 || $nb === "0")//now you are sure that $nb was a float and $floatNb is the float representation
If you got international numbers, use the number formatter from intl extension :
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
$num = "1.234.567,891";
echo numfmt_parse($fmt, $num)."\n";
Regex are NEVER good for type checking