Just wanted to get an opinion of the following regex for checking a string against a comma separated float value.
Code: Select all
<?php
$test = array("123", "123.45", "one.34", "123.45.67", "one", 12.52, "", "1,234.50", "1,234,567.89", "1,23");
foreach ($test as $test_val) {
echo "<br>Is $test_val valid? ";
if(isFloat($test_val)) echo " Yes"; else echo "No";
}
function isFloat($value) {
return preg_match('/\A[\d]*(?:[,]{1}[\d]{3})*(?:[.]{1}[\d]*)?\z/', $value);
}
?>Any ideas? Any suggestions for making this better?
Cheers