0
<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,}" />

如何确保上面要输入的值是负值?

4

3 回答 3

0

使用模式没有任何把握。您应该检查一下服务器端。但是,如果您想使用模式来检查这一点,模式应该是\-[0-9]+

至于 PHP:

您只需在将其插入数据库之前检查该值:

if($_REQUEST['amount'] >= 0){ // $_REQUEST is generally for $_GET and $_POST
    echo "Incorrect amount given. Please try again.";
    die();
}
于 2013-08-12T11:08:58.620 回答
0

检查发布的值,例如

 $amount = $_POST['amount'];

 if($amount > 0) {
      //echo 'positive';
      $req_amt = (0 - $amount);
 } else {
      echo 'negative or 0';
 }
于 2013-08-12T11:26:44.817 回答
0

经过广泛协商后,我得出的结论是,这是最可行的答案......感谢所有帮助查询 $_REQUEST['amount'] = -$_REQUEST['amount'];

于 2013-08-17T07:46:55.173 回答