<input type="number" class="addme" value="'.$_REQUEST['pbill'].'" name="amount" min="0" required="required" placeholder="Enter amount of Pending Bills" title="Enter amount of Pending Bills" pattern="[0-9]{1,}" />
如何确保上面输入的值为负值?
答案 0 :(得分:0)
使用模式并不确定。你应该检查服务器端。但是如果您想使用模式来检查这个,那么模式应该是\-[0-9]+
至于PHP:
您只需在将值插入数据库之前检查该值:
if($_REQUEST['amount'] >= 0){ // $_REQUEST is generally for $_GET and $_POST
echo "Incorrect amount given. Please try again.";
die();
}
答案 1 :(得分:0)
检查发布的值,例如
$amount = $_POST['amount'];
if($amount > 0) {
//echo 'positive';
$req_amt = (0 - $amount);
} else {
echo 'negative or 0';
}
答案 2 :(得分:0)