[英]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.