Php 使表单允许输入最小数字10或更高

Php 使表单允许输入最小数字10或更高,php,Php,我在我的网站上有一个表格,我想让允许输入的最小数字为10或更高 以下是该表单的代码: <input type="number" id="amount" onchange="updateInput(this.value)" class="form-control" value="10" placeholder="1.00" autocomplete="off" required> 谁能帮我完成这件事 谢谢将值更改为min <input type="number" id="a

我在我的网站上有一个表格,我想让允许输入的最小数字为10或更高

以下是该表单的代码:

<input type="number" id="amount" onchange="updateInput(this.value)" class="form-control" value="10" placeholder="1.00" autocomplete="off" required>

谁能帮我完成这件事


谢谢

更改为
min

<input type="number" id="amount" onchange="updateInput(this.value)" class="form-control" min="10" placeholder="1.00" autocomplete="off" required>

值更改为
min

<input type="number" id="amount" onchange="updateInput(this.value)" class="form-control" min="10" placeholder="1.00" autocomplete="off" required>

这个问题带有PHP标签。首先,您需要考虑雅伊姆对客户端的回答(并且请为任何表单输入添加名称属性。在这种情况下,我们假设您将名称设置为“金额”),并且在后端PHP这样做:

<?php
$error = '';
$amount = ''; // default value;

if (isset($_REQUEST['amount'])) {
    $amount = intval($_REQUEST['amount']); // get the value as number
    if ($amount < 10) $error = 'the amount is under 10 and not acceptable';
}
echo $error;
?>

这个问题带有PHP标签。首先,您需要考虑雅伊姆对客户端的回答(并且请为任何表单输入添加名称属性。在这种情况下,我们假设您将名称设置为“金额”),并且在后端PHP这样做:

<?php
$error = '';
$amount = ''; // default value;

if (isset($_REQUEST['amount'])) {
    $amount = intval($_REQUEST['amount']); // get the value as number
    if ($amount < 10) $error = 'the amount is under 10 and not acceptable';
}
echo $error;
?>


这很有效。我实际上是在价值之外加上了这个。因此,当该表单加载时,数字10已经输入,并且人们不能使用滚动来滚动到10以下。但是,如果有人手动输入较小的数字,他们仍然可以这样做。我也能以某种方式防止吗?负数的值也可以手动输入。(例-100)。我能不能完全阻止10以下的内容被输入到该表单中?使用javascript检测变化,如果它小于最小值,则将其设置为10我不知道怎么做。你能告诉我怎么做吗?我会在谷歌上搜索,然后试着把它完成。但如果你能告诉我怎么做,我将不胜感激。谢谢你的努力。我实际上是在价值之外加上了这个。因此,当该表单加载时,数字10已经输入,并且人们不能使用滚动来滚动到10以下。但是,如果有人手动输入较小的数字,他们仍然可以这样做。我也能以某种方式防止吗?负数的值也可以手动输入。(例-100)。我能不能完全阻止10以下的内容被输入到该表单中?使用javascript检测变化,如果它小于最小值,则将其设置为10我不知道怎么做。你能告诉我怎么做吗?我会在谷歌上搜索,然后试着把它完成。但如果你能告诉我怎么做,我将不胜感激。谢谢