Validating U.S. Currency
<?php
$regex = "/^\\$?(\d{1,3}(,\d{3})*|\d+)\.\d\d$/";
$values = array(
"1,123.00",
"1123.00"
);
foreach ($values as $value) {
if (preg_match($regex, $value)) {
echo "'" . $value . "' is a valid number.\n";
} else {
echo "'" . $value . "' is NOT a valid number.\n";
}
}
?>
Related examples in the same category