这里我试图对html输入表单进行验证。如果输入不是数字,我想返回false。如果提供除number之外的任何其他内容作为输入,我想返回false。
我该怎么做?数字验证的模式是什么
<form class="form-horizontal" name="product-form" method="post" action="go.php" role="form" enctype="multipart/form-data" onsubmit="return validateForm();">
<div class="form-group">
<label class="control-label col-sm-2" for="product_price">Product Price</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="product_price" id="product_price" placeholder="36000" required>
</div>
</div>
</form>
的Javascript
function validateForm() {
var x = document.forms["product-form"]["product_price"].value;
if (x == null || x == "") {
alert("price must have only numbers");
return false;
}
}
答案 0 :(得分:0)
<form class="form-horizontal" name="product-form" method="post" action="go.php" role="form" enctype="multipart/form-data">
<div class="form-group">
<label class="control-label col-sm-2" for="product_price">Product Price</label>
<div class="col-sm-10">
<input type="number" class="form-control" name="product_price" id="product_price" placeholder="36000" required>
</div>
</div>
</form>