1

how to check input text before POST operation? it must be numbers only

<form method="post" action="credit.php">
Сумма кредита: <input type="text" name="sum"> <br />
первый взнос: <input type="text" name="pv"> <br />
Срок: <input type="text" name="srok"> <br />
Процентная ставка: <input type="text" name="percent"> <br />
<input type="submit">
</form>

sorry for my bad english.

2
  • Are you using a library such as JQuery? Jquery has plugins like Jquery.Validate Commented May 29, 2010 at 20:22
  • Do you use jQuery or other JavaScript framework? Also, suggestion: use labels to wrap text related to each input, and maybe div to wrap label and input, instead of breaks. Commented May 29, 2010 at 20:23

1 Answer 1

4

Use some kind of javascript..

<form method="post" action="credit.php" onsubmit="validateForm()">
<input type="text" name="pv" id="pv"> <br />
....
</form>


<script type="text/javascript">
function validateForm() {
  var result =  /^\d+$/.test(document.getElementById('pv').value);
  return result

}
</script>

If your onsubmit returns false, the form won't go. If it returns true, the form will submit.

Sign up to request clarification or add additional context in comments.

4 Comments

how to alert, when user's input is not a number?
and at input may be decimal (fraction). how to be with this?
How to alert? alert("Please enter a number"); return false;
Make a regular expression to check what you want. A regular expression for decimal is ^\d*.?\d*$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.