You can validate with regex, or use something like:
function isValidPrice($price) {
if ($parts = explode('.', $price)) {
$count = count($parts);
if ($count == 1) {
return ctype_digit($parts[0]);
} elseif ($count == 2) {
return ctype_digit($parts[0]) && ctype_digit($parts[1]);
} else {
return false;
}
} else {
return false;
}
}
EDIT:
with regex, probably something like:
function isValidPrice($price) {
return preg_match('/^[0-9]+(\.[0-9]+)?$/', $price);
}