php和regex,如果用户输入它,如何剥离美元符号和百分号?

ama*_*a89 1 php regex ereg-replace

基本上,这需要做的只是接受一个价格值,只能是40或39.95或100.09或4等,如果用户输入一个数字以外的任何东西进入该字段,它返回错误.

我的问题:如何更改它以便如果用户在输入字段中输入一个美元符号,它只是被剥离而不是在该特定情况下返回错误?


if (ereg_replace('/^\d+(\.\d{2})?$/', $_POST['itemAmt'])) {
    echo '<h1>The original cost of the item: $' . $_POST['itemAmt'] . ' </h1>';
} else {
    echo '<h1 style="color:red; font-weight:900;">The price value was not numeric, try again :) </h1><br>';
}
Run Code Online (Sandbox Code Playgroud)

zer*_*kms 6

$itemAmt = str_replace(array('$', '%'), '', $_POST['itemAmt']);
Run Code Online (Sandbox Code Playgroud)