小编ama*_*a89的帖子

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

基本上,这需要做的只是接受一个价格值,只能是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)

php regex ereg-replace

1
推荐指数
1
解决办法
2971
查看次数

标签 统计

ereg-replace ×1

php ×1

regex ×1