validation - How to validate input in javascript for numbers -
this question has answer here:
- html text input allows numeric input 53 answers
here trying validation html input form. here want return false if input not number. want return false if else other number supplied input.
how can this? pattern number validation
<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 numbers"); return false; } }
or can use html5 input type number
<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>
Comments
Post a Comment