[英]How to set a Negative Value to an Input box in php
<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-9]+
至於PHP:
您只需在將值插入數據庫之前檢查該值:
if($_REQUEST['amount'] >= 0){ // $_REQUEST is generally for $_GET and $_POST
echo "Incorrect amount given. Please try again.";
die();
}
檢查過帳的值,例如
$amount = $_POST['amount'];
if($amount > 0) {
//echo 'positive';
$req_amt = (0 - $amount);
} else {
echo 'negative or 0';
}
經過廣泛的咨詢,我得出的結論是,這是最可行的答案...感謝查詢$ _REQUEST ['amount'] =-$ _ REQUEST ['amount'];的所有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.